Place a QWidget into a Main Window - playing with mplayer2



  • 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


  • Lifetime Qt Champion

    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



  • 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.


  • Lifetime Qt Champion

    How are you sending the command to mplayer ?



Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.