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. Place a QWidget into a Main Window - playing with mplayer2
Forum Update on Monday, May 27th 2025

Place a QWidget into a Main Window - playing with mplayer2

Scheduled Pinned Locked Moved General and Desktop
mplayerembedded applicwinidmplayer2
4 Posts 2 Posters 2.0k Views
  • 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.
  • P Offline
    P Offline
    Poulad
    wrote on 30 Sept 2015, 21:46 last edited by
    #1
    Hello guys

    I am developing an application in GNU/Linux which uses mplayer2. After a lot of search, I finally managed to find a way to play a video file inside a window using mplayer2.
    In the applicatoin when main window executes, it creates a QWidget(with null parent) and gets its WinId; then starts a mplayer2 process and passes QWidget's WinId to mplayer2 process.

      process->start( "mplayer2 -wid " + QString::number( (quint64) (widget->winId()) + " input.mp4" );
    

    mplayer2 starts playing video inside the widget object. now i have two problems.

    • How can I place the widget into the mainwindow? for example in a frame or layout so it will be fixed there. (I don't want it to be played in a seperate window)?

    • Is it possible to enable program to show a context menu whenever the user right-clicks on the mplayer2(or widget object)?

    tnx for your reply

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 30 Sept 2015, 21:51 last edited by
      #2

      Hi and welcome to devnet,

      I assume your MainWindow is a QWidet, so something like:

      QVBoxLayout *layout = new QVBoxLayout(this);
      layout->addWidget(yourMplayerWidget);
      

      and it should go there.

      For the context menu part, have a look at Menus example

      Hope it helps

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

      1 Reply Last reply
      0
      • P Offline
        P Offline
        Poulad
        wrote on 30 Sept 2015, 23:01 last edited by Poulad
        #3

        thank you. I implemented mouse events in a class which inherits QWidget. So the widget responses to mouse events well although mplayer2 screen doesn't response to any key event (like p for pause or 0 for volume down).
        But the first problem didn't solve even using your suggestion.
        mplayer2 process uses argument -wid [windowID]]. I created my widget on heap with no parent to give it a window.

        MainWindow::MainWindow(QWidget *parent)
          :  QWidget(parent)
        {
          ...
          PlayerWidget *playerWidget = new PlayerWidget(0);
          playerWidget->show();
          ...
        }
        

        hence it has a window, i passed it's winId to mplayer2. I believe if i change the playerWidget's parent by any mean(such as setting it a central widget), it loses the winId.

        • How can i make the widget borderless? without any border arround, i might be able to stick it to somewhere of my main window.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 1 Oct 2015, 19:19 last edited by
          #4

          How are you sending the command to mplayer ?

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

          1 Reply Last reply
          0

          2/4

          30 Sept 2015, 21:51

          • Login

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