Interaction between QGraphicsVideoItem, QGraphicsScene, QGraphicsView
-
Hello All,
it is the first time that I interface with the world of scenes and views. I've read some theory, and now I'm doing some experiments to better understand how to use it all.
I created this simple example:
int main(int argc, char *argv[]) { QApplication::setAttribute(Qt::AA_ShareOpenGLContexts, true); QApplication a(argc, argv); QString url = "gst-pipeline: videotestsrc ! xvimagesink name=\"qtvideosink\""; QGraphicsVideoItem* item = new QGraphicsVideoItem; item->setSize(QSizeF(500, 480)); QMediaPlayer p; p.setVideoOutput(item); p.setMedia(QMediaContent()); //discard p.setMedia(QUrl(url)); p.play(); QGraphicsScene* scene = new QGraphicsScene; QGraphicsRectItem *rect = scene->addRect( 10,10, 50, 70, QPen(Qt::black), QBrush(Qt::red)); rect->setFlag(QGraphicsItem::ItemIsMovable); QGraphicsView view(scene); view.scene()->addItem(item); view.show(); return a.exec(); }
But what I get is not as imagined:
As you can see from the image above, I get two windows, one containing View and Scene, and a second one containing the VideoItem.
Could you please tell me what/where I'm doing wrong?Qt: 5.15.2, OS: Debian 12
Thanks
-
@Sierra said in Interaction between QGraphicsVideoItem, QGraphicsScene, QGraphicsView:
Could you please tell me what/where I'm doing wrong?
When you tell us, what you want to do or what you expect... :)
You have your
QMediaPlayer
with your video in one window and yourQGraphicsView
+-scene
with your red rect in another widget. -
I suspect you must not call "play()" until the QGraphicsView is ready.
Look at the order of calls in the doc's example