Best practice for making a video widget fullscreen



  • What is the best way to make a child widget (video widget) fullscreen? I have a video widget (from VLC-Qt) as a child widget in my application. I've created the GUI so far using Qt Designer and everything is currently in a grid layout.

    I can detach the child widget by setting the parent to nullptr and calling showFullScreen() on the widget to make it full screen. That works pretty well, but I have no idea how I can make the widget go back to its original location once I exit fullscreen mode since I'm using a grid layout.

    I'm probably going about this the wrong way and probably shouldn't use a grid layout anyways, but the grid layout has worked out well so far. Perhaps it would be easier if I used another layout system. Anyways, does anyone have an idea of what I can do here? I noticed that the Qt media player has fullscreen functionality built in, but I'm not sure how that works. I would really appreciate any help or feedback about this. This is my first time trying to create a media player.


  • Moderators

    @JordanHarris said:

    I can detach the child widget by setting the parent to nullptr and calling showFullScreen() on the widget to make it full screen.

    Just a small hint: You do not need to detach the widget by setting the parent to null. Instead use QWidget::setParent( parent, Qt::Tool )

    That works pretty well, but I have no idea how I can make the widget go back to its original location once I exit fullscreen mode since I'm using a grid layout.

    Why can't you simply read it to the layout? The same way you inserted it in the first place?



  • @raven-worx said:

    Just a small hint: You do not need to detach the widget by setting the parent to null. Instead use QWidget::setParent( parent, Qt::Tool )

    Ahh thank you for that tip. I ended up doing that, but how do you make it go back to a normal widget? I used setParent(parent, Qt::Subwindow) and it worked, but I'm not sure if that's the best way.

    Why can't you simply read it to the layout? The same way you inserted it in the first place?

    So I went to the generated UI file to see how it was adding the video widget to the grid layout and used that same code to add it back to the layout. It works perfectly now. :) Thank you very much for your help. I probably should've thought of that myself, but anyways I really appreciate the help.

    I should probably figure out a better layout system than just using the grid layout because I suspect that I'll have to change the code that adds the video widget back whenever I add something to the UI. I'll have to experiment with that when I can.


  • Moderators

    @JordanHarris
    ah sorry have overread that you were using QtDesigner.

    I am not sure if you should really use Qt::SubWindow flag. Normally this is only used by QMdiSubWindow? The suggested Qt::Tool of mine was already appropriate.
    Qt::Tool is a separate window which doesn't show up in the taskbar.
    Probably even better would be to use

    setParent( parent, Qt:Tool | Qt::CustomizeWindowHint | Qt::FramelessWindowHint );
    


  • Thank you for that suggestion. I'm going to try that as soon as I can. Yeah I shouldn't have at it to Qt::SubWindow. I should just set it back to Qt::Widget, which is the default. Also, I probably don't even need to be using the setParent() function. I could probably just use setWindowFlags() and be alright. Thanks for ask the help man. Just discussing this has made things clearer to me. I probably would've done something crazy to get full screen functionality if I didn't post this. It's working quite well now, even without those few changes mentioned earlier.



  • Just an update: I ended up just using a "container widget" that holds the video widget. This way I can just add the container widget to the layout and detach the video widget from the container when going full screen. Then I just add it back to the container instead of trying to add it to the layout exactly as it was. In my case, I'm actually using a QStackedWidget as the "container" since I need to switch the video out with other views anyways. It works out perfectly. This project is really coming along nicely. I'm loving Qt right now. :)


Log in to reply
 

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