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. How to add Qvideowidget to second mainwindow
Forum Updated to NodeBB v4.3 + New Features

How to add Qvideowidget to second mainwindow

Scheduled Pinned Locked Moved Solved General and Desktop
15 Posts 2 Posters 1.6k 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.
  • SGaistS SGaist

    Put a layout on that widget and add your video player to it.

    A Offline
    A Offline
    Allaye
    wrote on last edited by
    #5

    @SGaist it works but unfortunately that was not what i was thinking about,

    int main(int argc, char *argv[])
    {
    	QApplication a(argc, argv);
    	QApplication1 w;
    	QVideoWidget vw(&w);
    	vw.setGeometry(20, 20, 120, 140);
    	QMediaPlayer * mp = new QMediaPlayer(&w);
    
    		QString videoname = QFileDialog::getOpenFileName( &w,"choose video file", QDir::homePath());
    	  mp->setMedia(QUrl::fromLocalFile(videoname));
    	  mp->setVideoOutput(&vw);
    	     mp->play();
    	    w.setCentralWidget(&vw);
    
    	w.show();
    	return a.exec();
    }
    with the code above,  i just create an object of the main class and i passed the Qvideowidget to it
    but i cant do same to the other class...  so this code adds the Qvideowidget to the main Window form.. i dont know if am been understood
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #6

      Why don't you create that QVideoWidget directly in that second MainWindow ?

      By the way, did you really named your class QApplication1 ? If so, that's a very bad idea.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      A 1 Reply Last reply
      0
      • SGaistS SGaist

        Why don't you create that QVideoWidget directly in that second MainWindow ?

        By the way, did you really named your class QApplication1 ? If so, that's a very bad idea.

        A Offline
        A Offline
        Allaye
        wrote on last edited by
        #7

        @SGaist that ia what i wanted to do, if you can help, the QApplication1 is just a test class nothing serious

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #8

          Then go to the constructor of that class and add your video widget related code there.

          Even if nothing serious you should rather use FooClass than deriving names from one of Qt's own classes. You would be surprise by how fast things get serious when developing.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          A 1 Reply Last reply
          0
          • SGaistS SGaist

            Then go to the constructor of that class and add your video widget related code there.

            Even if nothing serious you should rather use FooClass than deriving names from one of Qt's own classes. You would be surprise by how fast things get serious when developing.

            A Offline
            A Offline
            Allaye
            wrote on last edited by
            #9

            @SGaist still the same result, no difference

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #10

              Did you set your video player in a layout that you set on your secondary MainWindow all within the constructor of that class ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              A 1 Reply Last reply
              0
              • SGaistS SGaist

                Did you set your video player in a layout that you set on your secondary MainWindow all within the constructor of that class ?

                A Offline
                A Offline
                Allaye
                wrote on last edited by
                #11

                @SGaist 0_1558300851631_Screenshot (10).png i want the video inside the right window

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #12

                  Did you do exactly how I suggested you to do ?

                  Can you show the actual code you are using ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  A 1 Reply Last reply
                  0
                  • SGaistS SGaist

                    Did you do exactly how I suggested you to do ?

                    Can you show the actual code you are using ?

                    A Offline
                    A Offline
                    Allaye
                    wrote on last edited by
                    #13

                    @SGaist thanks for your time, this are the code

                    QWidget *window = new QWidget;
                    	QFormLayout *layout = new QFormLayout;
                    	QVideoWidget * vw = new QVideoWidget();
                    	QMediaPlayer * mp = new QMediaPlayer(vw);
                    	 QPushButton *PAUSE = new QPushButton("Pause");
                    	 QString vidstring = QFileDialog::getOpenFileName(this, "Select video file", QDir::homePath());
                    	
                    	 //layout->addWidget(PAUSE);
                    	 mp->setMedia(QUrl::fromLocalFile(vidstring));
                    	 mp->setVideoOutput(vw);
                    	  layout->addWidget(vw);
                    	 vw->setGeometry(100, 100, 500, 500);
                    	 vw->show();
                    	 vw->setAttribute(Qt::WA_DeleteOnClose);
                    	 window->setLayout(layout);
                    	 mp->play();
                    	 window->show();
                    
                    A 1 Reply Last reply
                    0
                    • A Allaye

                      @SGaist thanks for your time, this are the code

                      QWidget *window = new QWidget;
                      	QFormLayout *layout = new QFormLayout;
                      	QVideoWidget * vw = new QVideoWidget();
                      	QMediaPlayer * mp = new QMediaPlayer(vw);
                      	 QPushButton *PAUSE = new QPushButton("Pause");
                      	 QString vidstring = QFileDialog::getOpenFileName(this, "Select video file", QDir::homePath());
                      	
                      	 //layout->addWidget(PAUSE);
                      	 mp->setMedia(QUrl::fromLocalFile(vidstring));
                      	 mp->setVideoOutput(vw);
                      	  layout->addWidget(vw);
                      	 vw->setGeometry(100, 100, 500, 500);
                      	 vw->show();
                      	 vw->setAttribute(Qt::WA_DeleteOnClose);
                      	 window->setLayout(layout);
                      	 mp->play();
                      	 window->show();
                      
                      A Offline
                      A Offline
                      Allaye
                      wrote on last edited by
                      #14

                      @Allaye probably my problem is how can i call the second window and set the QVideowidget to display on it rather than displaying on it own... thanks

                      A 1 Reply Last reply
                      0
                      • A Allaye

                        @Allaye probably my problem is how can i call the second window and set the QVideowidget to display on it rather than displaying on it own... thanks

                        A Offline
                        A Offline
                        Allaye
                        wrote on last edited by
                        #15

                        i tried this and it worked i made the QVideowidget the child of the second window and it worked...

                        QVideoWidget *vw = new QVideoWidget() ;
                        
                        QMediaPlayer * mp = new QMediaPlayer(vw);
                        
                            QString vidstring = QFileDialog::getOpenFileName(this, "Select video file", QDir::homePath());
                        
                            mp->setMedia(QUrl::fromLocalFile(vidstring));
                            mp->setVideoOutput(vw);
                            vw->setGeometry(100, 100, 500, 500);
                          vw->setParent(this);
                            vw->show();
                            mp->play();
                        
                        
                        }
                        
                        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