Nothing Special   »   [go: up one dir, main page]

Rendering A QGraphicsScene With QGraphicsVideoItem To QImage - QT

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

3/24/2020 Rendering a QGraphicsScene with QGraphicsVideoItem to QImage - qt

Develop Reference Home About Us Contact Us


ios excel sql-server .net django

Categories
Rendering a QGraphicsScene with QGraphicsVideoItem to QImage - qt
HOME
sql-server
ag-grid
#1 VMware Backup & Recovery
aplpy Ad
laravel-5.8
Trusted by more than 350k customers worldwide. Try a F
adobe
Ad 30-day Trial!
split
esp32 Veeam Software
fipy
echarts Open
gitbook
functor This part is solved
tridion I want to render a QGraphicsScene with QGraphicsVideoItem to QImage. Everything works when the QGraphicsScene is just with a QGraphicsTe
rmi However, if I replace QGraphicsTextItem with a QGraphicsVideoItem, it fails to get a correct image output.
chainer How to fix this? Thanks...
aws-step-functions following codes are to test this problem.
google-static-maps #include <QApplication>
charles-proxy #include <QGraphicsScene>
wav #include <QMediaPlayer>
pythonanywhere #include <QGraphicsVideoItem>
hashtag #include <QImage>
scikit-multilearn #include <QGraphicsView>
siemens int main(int argc, char *argv[])
lldb {
clickstream QApplication a(argc, argv);
openproject QGraphicsScene scene;
delphi-10.2-tokyo /* part 1. videoItem */
openbravo QMediaPlayer* videoPlayer = new QMediaPlayer;
strawberry-perl QGraphicsVideoItem* screen = new QGraphicsVideoItem;
openlayers-5 videoPlayer->setVideoOutput(screen);
clustered-index scene.addItem(screen);
jung videoPlayer->setMedia(QUrl::fromLocalFile("./data/Taylor Swift - Blank Space.mp4"));
minimize videoPlayer->play();
imagemap videoPlayer->setVolume(100);
updates /* part 2. textItem */
video-editing /*QGraphicsScene scene;
windows-server-2008-r2 QGraphicsTextItem* text = new QGraphicsTextItem("aaaaaaa");
usbserial scene.addItem(text);*/
azul-zulu QGraphicsView view(&scene);
ion-select view.resize(1920, 1080);
jquery-select2-4 view.show();
distributed-caching videoPlayer->pause();
rvest QImage image(1920, 1080, QImage::Format_ARGB32);
msi-patch image.fill(Qt::blue);
pdflatex QString pngName = "scene.png";
data-science-experience QPainter painter(&image);
consensus painter.setRenderHint(QPainter::Antialiasing);
sql-query-store scene.render(&painter);
stackage image.save(pngName);
ls return a.exec();
windows-server-2008 }
webextension-polyfill add the following in your .pro file may help : )
graphql-ruby QT += core gui
.net-2.0 QT += core
aurelia-dialog #QT += 3d
mixins QT += gui
face-id QT += multimedia
ultrawingrid QT += widgets
plottable.js QT += multimediawidgets
snowplow new Question
openoffice-writer In my project I want to render a video in a QGLView Window(Qt3D). However, QGraphicsView and QGLView seems can not be rendered at the sa
pweave don't use QGLView's show() method, I can get the video frames. If I use QGLView's show() method, I cannot get correct frames...
viewport So how could I realize the idea above?
phpgraphlib
xamarin-test-cloud The video is usually decoded and rendered using HW acceleration, so asking for the widget to be painted like that might not work at all, or at leas
binary-decision-diagram the actual video player backend.
inline-formset You could use QScreen::grabWindow (assuming Qt 5, it was QPixmap::grabWindow in Qt 4), after the screen is actually rendered. To actually hav
rpostgresql you need to grab the screenshow when video is actually showing, so you have to do it once the event loop is running and window is actually show
facebook-widgets

https://ios.developreference.com/article/18582497/Rendering+a+QGraphicsScene+with+QGraphicsVideoItem+to+QImage 1/6
3/24/2020 Rendering a QGraphicsScene with QGraphicsVideoItem to QImage - qt
outpan by overrding showEvent or just using QTimer.
turn If you want a screenshot of both the video and the GUI without actually showing the window, I'm not sure how to go about that.
parseexception
jazz
cl.exe
javax.mail Related
google-guava-cache
spotify-app
m2crypto How to create a VTK Chart in a QVTKWidget
lwuit I tried now for 2 hours creating a simple chart with vtk without any success. It just does not render anything and I cannot call the view->getRend
mongodb-mms >render () function. It results in an exception.
sqlmx What I understood so far is:
autodiscovery vtkContextView* view = vtkContextView::New ();
transcoding QVTKWidget* widget = new QVTKWidget ();
android-alarms widget->setRenderWindow (view->getRenderWindow ());
named-query After creating chart and adding it...
start-stop-daemon view->getRenderer ()->render ();
ardor3d I'm using vtk 7.1, qt 5.7 with vs15.
jquery-mobile-checkbox I also tried to find a full example in the Internet but I haven't found any complete.
qt4.6 Could someone show an example of how to create such a vtk chart with qt?
dmoz According to this discussion on the vtk mailing list the widget and the view can be connected like this:
cocoalibspotify-2.0 widget->SetRenderWindow(view->GetRenderWindow());
jquery-ui-selectable view->SetInteractor(widget->GetInteractor());
failing-tests It seems like you're missing that second line. See below for a complete example.
openrasta #include <QtWidgets>
ef4-code-only #include <QVTKWidget.h>
addchild #include <vtkSmartPointer.h>
asp.net-routing #include <vtkDoubleArray.h>
corporate #include <vtkChartXY.h>
oggvorbis #include <vtkTable.h>
#include <vtkPlot.h>
#include <vtkContextView.h>
#include <vtkContextScene.h>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
// Prepare plot data
auto table = vtkSmartPointer<vtkTable>::New();
table->AddColumn(vtkSmartPointer<vtkDoubleArray>::New());
table->AddColumn(vtkSmartPointer<vtkDoubleArray>::New());
table->GetColumn(0)->SetName("X");
table->GetColumn(1)->SetName("Y");
table->SetNumberOfRows(100);
for(int i = 0; i < 100; ++i)
{
table->SetValue(i, 0, i);
table->SetValue(i, 1, i*i);
}
// Create chart, view and widget
auto chart = vtkSmartPointer<vtkChartXY>::New();
auto line = chart->AddPlot(vtkChart::LINE);
line->SetInputData(table, 0, 1);
auto view = vtkSmartPointer<vtkContextView>::New();
view->GetScene()->AddItem(chart);
auto widget = new QVTKWidget();
view->SetInteractor(widget->GetInteractor());
widget->SetRenderWindow(view->GetRenderWindow());
widget->show();
return app.exec();
}
I had exactly the same problem (Qt 5.9, VTK 7.1) and the solution of stfnp didn't work for me. What did work was a somewhat opposite approac
source code of the question, i.e.:
view->SetRenderWindow(widget->GetRenderWindow());
instead of
widget->setRenderWindow(view->getRenderWindow ());
which also seems more natural for me (asking the view to render in the render window provided by the widget).

QVideoWidget: Video is cut off


I want to play a video in a Qt Application. This is my code so far:
#include <QApplication>
#include <QWidget>
#include <QMediaPlayer>
#include <QVideoWidget>
#include <QUrl>
#include <iostream>
using namespace std;
const int WIDTH = 1280;

https://ios.developreference.com/article/18582497/Rendering+a+QGraphicsScene+with+QGraphicsVideoItem+to+QImage 2/6
3/24/2020 Rendering a QGraphicsScene with QGraphicsVideoItem to QImage - qt
const int HEIGHT = 720;
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget window;
window.resize(WIDTH, HEIGHT);
window.setWindowTitle("Video Test");
window.show();
QMediaPlayer *player = new QMediaPlayer();
player->setMedia(QUrl::fromLocalFile("/Path/To/Video.mp4"));
QVideoWidget *videoWidget = new QVideoWidget(&window);
player->setVideoOutput(videoWidget);
videoWidget->resize(WIDTH, HEIGHT);
videoWidget->show();
player->play();
return app.exec();
}
The problem: The video is shown and plays back normally, but the video does not resize to fit in the QVideoWidget. The part of the video that is
the widget is cut off.
Thanks in advance!
EDIT: I reduced the code and noticed, that when the application starts the video is cut off, but when I resize the window using the mouse it actua
size:
#include <QApplication>
#include <QWidget>
#include <QMediaPlayer>
#include <QVideoWidget>
#include <QUrl>
#include <iostream>
using namespace std;
const int WIDTH = 1280;
const int HEIGHT = 720;
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QMediaPlayer *player = new QMediaPlayer();
QVideoWidget *videoWidget = new QVideoWidget();
player->setVideoOutput(videoWidget);
player->setMedia(QUrl::fromLocalFile("/Path/To/Video.mp4"));
player->play();
videoWidget->resize(WIDTH/3, HEIGHT/3);
videoWidget->show();
return app.exec();
}
After many hours of looking for the error, I think this is a bug in Qt on OSX, as I watched this YouTube video https://www.youtube.com/watch?v=
VBX0 and tried out the code.
In the video scaling works fine, but on my machine not.
For anyone in 2016, QVideoWidget is still busted. However, use a QGraphicsView widget, which holds a scene graph, and add a single
QGraphicsVideoItem to the scene graph. Seems to work...
well, except that it's not exactly centered. and there's a 1px border on the left. and it hangs going into full screen most of the time. and I get erro
"updateVideoFrame called without AVPlayerLayer (which shouldn't happen". Progress!
.. oh, and it takes up about 10x the cpu too.
You know what does work, and works great? GStreamer. Thank you, gstreamer. Even integrating it in python/qt works fabulously.
I ran into a similar problem in PyQt5. I worked around it by setting the geometry of the QVideoWidget to its current geometry before playing the
guessing something in the resizeEvent signal must handle the scaling of the media and isn't triggered when initialized.
Usually the scale mode dictates how the video fills the widget.
The scale mode FitInView will force the video to fill the view keeping aspect ratio.
However, this scale mode should be the default. You can try to set it manually:
QVideoWidget *videoWidget = new QVideoWidget(&window);
videoWidget->setScaleMode(Phonon::VideoWidget::FitInView);
player->setVideoOutput(videoWidget);
After playing, I resized the QVideoWidget by 1 and then resized to original size.
Definitely "fudge", but this works for me until I find a real solution:
(working with PyQt5 and High Sierra)
s1 = self.MediaFrame.size() # QVideoWidget
s2 = s1 + QSize(1, 1)
self.MediaPlayer.play() # QMediaPlayer
self.MediaFrame.resize(s2) # enlarge by one pixel
self.MediaFrame.resize(s1) # return to original size

3D model from a single photo


Ad A recognizable avatar created in runtime from a sin
photo!
Ad
Itseez3D

Open

https://ios.developreference.com/article/18582497/Rendering+a+QGraphicsScene+with+QGraphicsVideoItem+to+QImage 3/6
3/24/2020 Rendering a QGraphicsScene with QGraphicsVideoItem to QImage - qt

Understanding QGraphicsScene in Qt
I am trying to understand the basics of Qt. After going through some posts, I came to know that ui_mainwindow.h gets created by UIC tool and t
ui_mainwindow.h contains the information about my form/ui that I created.
In my GUI, I have taken a pushbutton and a graphics view. I want a simple image (which I am creating inside the program itself) gets displayed
graphicsView. I am trying to do it with two ways (for learning purpose):
I can write the code inside on_pushButton_clicked()(i.e. the slot of my push_button).
I am trying to put the image from the main()
Problem: I am done with the first method. I used the following lines of code inside on_pushButton_clicked() and it worked.
void MainWindow::on_pushButton_clicked()
{
//Display image in the graphics viewer
Mat img(200,200, CV_8UC3, Scalar(255,0,0));
QImage image( img.data, img.cols, img.rows, img.step, QImage::Format_RGB888 );
QGraphicsScene* scene = new QGraphicsScene();
QGraphicsPixmapItem* item = new QGraphicsPixmapItem(QPixmap::fromImage(image));
scene->addItem(item);
ui->graphicsView->setScene(scene);
}
Now, I want to do the similar thing from the main(). To do that, now my main() looks like following:
#include "mainwindow.h"
#include <QApplication>
//For image
#include <QImage>
#include <QPixmap>
#include <QGraphicsPixmapItem>
//#include "ui_mainwindow.h"
//OPENCV Headers
#include <opencv2/opencv.hpp>
#include <opencv2/core.hpp>
#include <opencv2/imgcodecs/imgcodecs.hpp>
using namespace cv;
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
//Display image in the graphics viewer
Mat img(200,200, CV_8UC3, Scalar(255,0,0));
QImage image( img.data, img.cols, img.rows, img.step, QImage::Format_RGB888 );
QGraphicsScene* scene = new QGraphicsScene();
QGraphicsPixmapItem* item = new QGraphicsPixmapItem(QPixmap::fromImage(image));
scene->addItem(item);
w.ui->graphicsView->setScene(scene);
w.show();
return a.exec();
}
The above code written inside the main() works if I put #include "ui_mainwindow.h" in main.cpp. But if I comment #include "ui_mainwindow.h" an
>graphicsView->setScene(scene); then, it throws error for the QGraphicsScene* scene = new QGraphicsScene();.
Error is main.cpp:32: error: allocation of incomplete type 'QGraphicsScene' QGraphicsScene* scene = new QGraphicsScene();
QUESTIONS: Why is the connection between QGraphicsScene and "ui_mainwindow.h". I understand that I need "ui_mainwindow.h" for the line
>graphicsView->setScene(scene); becasue there I am using my ui but I don't understand the need for QGraphicsScene.
If You want to draw only static image better use just QLabel and set in some image
QImage *image = new QImage (":/prefix/image/vl.jpg" );
QLabel *magelab = new QLabel();
magelab->setPixmap(QPixmap::fromImage(*image));
Generaly QGraphicsScene better using with connection QGraphicsView. That is mean QGraphicsView set some object (scene) from QGraphics
like:
class SomeObject : public QGraphicsView
{
Q_OBJECT
public:
explicit Schemat(QWidget *parent = 0);
private:
QGraphicsScene *scene;
};
and source
Schemat::Schemat( QWidget *parent) : QGraphicsView(parent)
{
scene = new QGraphicsScene(this);
this->setScene(scene);
// to Your scene You can add some image for example
scene->addPixmap(SOME_PIXMAP)
}
Then You create main window and add with Your QGraphicsView, for example as some part QGroupBox
void MainWindow::SetupSchemat()
{
schema = new Schemat();

https://ios.developreference.com/article/18582497/Rendering+a+QGraphicsScene+with+QGraphicsVideoItem+to+QImage 4/6
3/24/2020 Rendering a QGraphicsScene with QGraphicsVideoItem to QImage - qt
QGroupBox *schbox;
QHBoxLayout *hschbox;
schbox = new QGroupBox(this);
hschbox = new QHBoxLayout(this);
schbox->setTitle("SomeScene");
hschbox->addWidget(schema); //add scene to layout
schbox->setLayout(hschbox);
}
QGraphicsScene is like some part of Your MainWindow on which you can make some animation, You can something draw. QGraphicsScene is
to using if You want use animation not only static image it supplies more option to manipulate image (ex scaling, catch mouse click, manage via
others object), and other object each should be animate or just display. To QGraphicsScene You can add some QGraphicsItem in turn each QG
can moving onto QGraphicsScene with particular conditions defined erly or in flow. Together QGraphicsView, QGraphicsScene and QGraphicsIt
created animation or just image in some part Your main window.
Also nice explained You will find here
https://www.youtube.com/watch?v=fmSs2mNGh9I

Create lifelike 3D characters from a single


sel e photo
Ad Create an account and add avatars to your product
Ad

Itseez3D

Open

QQuickWidget makes frameless and transparent QMainWindow totally disappear


I want to embed a quickwidget into a window. But the window will become totally invisible if I add a quickwidget as its child. I'm using Qt5.4.0/5.4
Windows10. Here is the snippets:
#include <QApplication>
#include <QMainWindow>
#include <QQuickWidget>
#include <QPushButton>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
auto window = new QMainWindow;
auto btn= new QPushButton("Can you see me?",window);
window->setWindowFlags(Qt::FramelessWindowHint|Qt::WindowStaysOnTopHint);
window->setAttribute(Qt::WA_TranslucentBackground, true);
//comment folloing code and everything will work fine.
auto quick = new QQuickWidget(window);
quick->setSource(QUrl("qrc:/main.qml"));
quick->move(40,40);
window->show();
return a.exec();
}
Edit: I'm trying creating a QQuickWidget with no parent. And make it look like an embed widget.
auto quick = new QQuickWidget();
quick->setWindowFlags(Qt::FramelessWindowHint|Qt::WindowStaysOnTopHint);
quick->setAttribute(Qt::WA_TranslucentBackground, true);
quick->setClearColor(Qt::transparent);
But, there is an severe problem. I can't click through its background although that is transparent. I have tested that the transparent background o
can be clicked through.
Edit2: After I rebooted the computer, the quickwidget became invisible again.WTF
Edit3: Qt5.5.0 seems to be OK.

Get CorelDRAW Suite 2020


Ad Fastest, smartest, and most connected graphics su
ever. Get it today!
Ad
CorelDRAW Graphics Suite

Shop Now

QGraphicsProxyWidget has clipped context menu in QGraphicsScene


The following code is based on the documentation of Graphics View Framework. I embed a QLineEdit in a QGraphicsScene and run the progra
right click the line edit in the scene I get a clipped context menu. The context menu of a QGraphicsProxyWidget is drawn by the scene as a child
QGraphicsProxyWidget so it get's clipped if the window is too small. I want all embedded widgets to show their context menus as top-level wind
do when not being embedded in a QGraphicsScene. I have tried the BypassGraphicsProxyWidget flag in two ways but it doesn't work as I want
Qt 4.8 / 5.0 on Linux and Windows. Same issue on all platforms.
How can I make the embedded widgets display normal, top-level context menus with native look? Overloading QGraphicsView's contextMenuE
native top-level context menu - could I do some sort of delegation and make QGraphicsView display the context menu of embedded widgets in
#include <QApplication>

https://ios.developreference.com/article/18582497/Rendering+a+QGraphicsScene+with+QGraphicsVideoItem+to+QImage 5/6
3/24/2020 Rendering a QGraphicsScene with QGraphicsVideoItem to QImage - qt
#include <QLineEdit>
#include <QGraphicsScene>
#include <QGraphicsProxyWidget>
#include <QGraphicsView>
int main(int argc, char **argv)
{
QApplication app(argc, argv);
QGraphicsScene scene;
QGraphicsProxyWidget *proxy = scene.addWidget(new QLineEdit(), Qt::BypassGraphicsProxyWidget);
QGraphicsView view(&scene);
view.setWindowFlags(Qt::BypassGraphicsProxyWidget);
view.show();
return app.exec();
}
Unfortunately, this is a known bug QTBUG-10683. A workaround is suggested in the last comment to the bug report.
You get native context menus by adding a QWidget that has the Qt::BypassGraphicsProxyWidget set. Children will render it's context menus as
native style.
#ifndef QGLPARENT_H
#define QGLPARENT_H
#include <QGLWidget>
#include <QGraphicsScene>
#include <QGraphicsProxyWidget>
#include <QGraphicsView>
class QGLParent : public QGraphicsView
{
private:
QGraphicsProxyWidget *child;
public:
QGLParent(QWidget *parent, QWidget *child) : QGraphicsView(parent)
{
setFrameShape(QFrame::NoFrame);
QGLFormat format(QGL::SampleBuffers);
format.setSwapInterval(1);
setScene(new QGraphicsScene());
setViewport(new QGLWidget(format));
//setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
child->setWindowFlags(Qt::BypassGraphicsProxyWidget);
this->child = scene()->addWidget(child);
}
protected:
void resizeEvent(QResizeEvent *event)
{
scene()->setSceneRect(QRect(QPoint(0, 0), event->size()));
child->resize(event->size().width(), event->size().height());
QGraphicsView::resizeEvent(event);
}
};
#endif

https://ios.developreference.com/article/18582497/Rendering+a+QGraphicsScene+with+QGraphicsVideoItem+to+QImage 6/6

You might also like