Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    My QGraphicsProxyWidget is not working, tested QWidget is

    General and Desktop
    qgraphicsproxyw qwidget qgraphicsscene video
    2
    3
    1153
    Loading More Posts
    • 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.
    • H
      houmingc last edited by houmingc

      Before removing comment when QGraphicsProxyWidget is created to view show(). this app is working.
      When this comment is removed & window assignment(setLayout, resize, show) commented, this app is no longer working( no longer showing 2 video side by side)
      Did i use QGraphicsProxyWidget correctly, i thought i did? Can someone comment on my error.

      @
      extern QStringList xmlID;
      extern QStringList xmlName;
      extern QStringList xmlValue;

      MainWindow::MainWindow(QWidget *parent) :
      QMainWindow(parent),
      ui(new Ui::MainWindow)
      {
      ui->setupUi(this);
      //
      QGraphicsScene scene;

      ml = new WidgetMarqueeLabel(this);
      ml->setDirection(1);
      ml->setSpeed(1);
      ml->setAlignment(Qt::AlignBottom);
      ml->setText(QString("%1").arg(xmlValue[2]));
      ml->setFont(QFont("Arial", 15,30));
      QGridLayout *layout= new QGridLayout;
      video();
      
      layout->addWidget(videoWidget,0,0);
      layout->addWidget(videoWidget1,0,1);
      layout->addWidget(ml,1,0,1,2);
      layout->setColumnStretch(0,10);
      layout->setColumnStretch(1,10);
      
      
      
      QWidget *window= new QWidget;
      window->setLayout(layout);
      

      // QGraphicsProxyWidget* proxy = scene.addWidget(window);

      // QGraphicsView view(&scene);
      // view.setWindowTitle("QWidget");
      // view.setFixedSize(800,900);
      // view.show();

         window->setLayout(layout);
         window->resize(1500,400);
         window->show();
      

      }

      //create new mediaplaylist, mediaplayer, Videowidget, playlist
      void MainWindow::video()
      {
      QString RealVideo1=xmlValue[0];
      playlist= new QMediaPlaylist();
      player= new QMediaPlayer;
      videoWidget = new QVideoWidget;
      playlist->addMedia(QUrl::fromLocalFile("/opt/night.mp4"));
      playlist->addMedia(QUrl::fromLocalFile("/opt/V7.mp4"));
      playlist->addMedia(QUrl::fromLocalFile("/opt/hotgirl.mp4"));
      playlist->addMedia(QUrl::fromLocalFile("/opt/bird.mp4"));
      playlist->addMedia(QUrl::fromLocalFile("/opt/arrow.mp4"));

      playlist->setPlaybackMode(QMediaPlaylist::Loop);
      playlist->setCurrentIndex(1);
      
      player->setPlaylist(playlist);
      player->setVolume(100);
      
      
      QString RealVideo2=xmlValue[1];
      playlist1= new QMediaPlaylist();
      playlist1->setPlaybackMode(QMediaPlaylist::Loop);
      player1= new QMediaPlayer;
      videoWidget1 = new QVideoWidget;
      playlist1->addMedia(QUrl::fromLocalFile("/opt/abc.mp4"));
      player1->setPlaylist(playlist1);
      player1->setVolume(0);
      
      
      player->setVideoOutput(videoWidget);
      player1->setVideoOutput(videoWidget1);
      playlist->setCurrentIndex(1);
      playlist1->setCurrentIndex(1);
      player->play();
      player1->play();
      

      }

      MainWindow::~MainWindow()
      {
      delete ui;
      }

      @

      1 Reply Last reply Reply Quote 0
      • A
        alex_malyu last edited by

        You are adding a few local variables in in MainWindow::MainWindow(QWidget *parent) {}
        which disappear as soon they go out of scope. and this happens way before your main window is shown.
        This includes QGraphicsScene scene; and QGraphicsView view(&scene);
        I bet it is not what you wanted.

        Instead you probably wanted put members to your MainWindow, so add QGraphicsScene scene; QGraphicsView view; to header file
        and just initialize them in constructor before anything else.

        H 1 Reply Last reply Reply Quote 0
        • H
          houmingc @alex_malyu last edited by

          After initializing them in constructor, the scene appears, video music is playing but
          video is not.

          @ header file
          QGraphicsProxyWidget* proxy;
          QGraphicsScene* scene;
          QGraphicsView* view;
          @

          @
          ui->setupUi(this);
          scene = new QGraphicsScene(this);

          ml = new WidgetMarqueeLabel(this);
          ml->setDirection(1);
          ml->setSpeed(1);
          ml->setAlignment(Qt::AlignBottom);
          ml->setText(QString("%1").arg(xmlValue[2]));
          ml->setFont(QFont("Arial", 15,30));
          QGridLayout *layout= new QGridLayout;
          video();
          layout->addWidget(videoWidget,0,0);
          layout->addWidget(videoWidget1,0,1);
          layout->addWidget(ml,1,0,1,2);
          layout->setColumnStretch(0,10);
          layout->setColumnStretch(1,10);
          
          QWidget *window= new QWidget;
          window->setLayout(layout);
          proxy= scene->addWidget(window);
          view = new QGraphicsView(scene);
          view->setFixedSize(800,900);
          view->show();
          

          @

          1 Reply Last reply Reply Quote 0
          • First post
            Last post