Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Interaction between QGraphicsVideoItem, QGraphicsScene, QGraphicsView

Interaction between QGraphicsVideoItem, QGraphicsScene, QGraphicsView

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 4 Posters 617 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sierra
    wrote on last edited by
    #1

    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:

    qtvideoitem.PNG

    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

    Pl45m4P 1 Reply Last reply
    0
    • S Sierra

      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:

      qtvideoitem.PNG

      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

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by
      #2

      @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 your QGraphicsView + -scene with your red rect in another widget.


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      S 1 Reply Last reply
      0
      • A Offline
        A Offline
        Asperamanca
        wrote on last edited by Asperamanca
        #3

        I suspect you must not call "play()" until the QGraphicsView is ready.
        Look at the order of calls in the doc's example

        1 Reply Last reply
        0
        • JoeCFDJ Offline
          JoeCFDJ Offline
          JoeCFD
          wrote on last edited by
          #4

          I guess you may need to create a qwidget and add a layout(QHBoxlayout) to it. Then add item and view to the layout.

          1 Reply Last reply
          0
          • Pl45m4P Pl45m4

            @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 your QGraphicsView + -scene with your red rect in another widget.

            S Offline
            S Offline
            Sierra
            wrote on last edited by
            #5

            @Pl45m4 What I would like to get is the QMediaPlayer "contained inside" the QGraphicsVideoItem, and the latter QGraphicsVideoItem "contained inside" the same schene where is the red rect.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved