QVideoWidget::setFullScreen(true) is not working properly first time when added QVideoWidget in QStackedLayout
-
@SGaist Can you please add your comments regarding this issue?
-
Hi,
That's because it's in a layout inside another widget.
On a side note, please format your code properly using coding tags or the
</>
button in the editing toolbar. -
Hi,
Thanks for the reply, but m_videoWidget is directly added into the layout in both cases. Can you please share code how I can fix this issue in QStackedLayout. I am sharing code again in which m_videoWidget is directly added in the layout.// In this case, m_videoWidget setFullScreen is not working properly. QStackedLayout *stackedLayout = new QStackedLayout; stackedLayout->addWidget(m_videoWidget); stackedLayout->setCurrentIndex(0); QBoxLayout *mainLayout = new QVBoxLayout; mainLayout->addLayout(stackedLayout, 1); setLayout(mainLayout); // In this case, m_videoWidget setFullScreen is working properly. void MediaPlayer::setPlayerLayout_old() { try { QBoxLayout *displayLayout = new QHBoxLayout; displayLayout->addWidget(m_videoWidget, 1); QBoxLayout *mainLayout = new QVBoxLayout; mainLayout->addLayout(displayLayout, 1); setLayout(mainLayout); } catch (...) { qCritical() << "MediaPlayer::setPlayerLayout: Exception occured. "; }
-
You have the take the widget out. You can't make arbitrary widgets full screen. They have to be top level widgets.
-
@SGaist As SGaist said, take your video widget out of the layout and set its parent to nullptr. Then set fullscreen mode to it. After your app exits fullscreen mode of this video widget, add video widget back to the layout with the original parent.
-
@JoeCFD Thanks for your reply. I am trying to understand what is the difference between using QStackedLayout and QHBoxLayout. As when I use QHBoxLayout, it works fine.
I am using QStackedLayout because I have 2 widgets:
- one is QVideoWidget which I am using to play video/audio files
- the second one is ImageView (QWidget derived class) which is used to show image files.
and I am switching between these 2 widgets based on media file. I have list of media files, if it is image, then show it and if it is video/audio, then play it.
I'll try what you have suggested and let you know how it goes. Thanks.
-
No, it's just the widget on top of the stack. Your QStackedLayout is itself set in another layout applied to your MediaPlayer widget which may or may not be a top level widget as we don't know how your use it.
-
@SGaist Very useful comments. At some point, controls widget (buttons to stop/play/next/previous media files) becomes active (by raise command) and at this point MediaPlayer is not top level widget. I'll update code as per your suggestion. Thank you so much for your help!
-
@SGaist Actually the same code is working fine after first click on controls widget. Before click, setFullScreen(true) did not work fine. That is very amazing thing. m_videoWidget->isFullScreen() returns true, but in reality, it is not fullscreen when app started.
How can I programmatically achieve user interaction behaviour? I called activateWindow in MediaPlayer constructor, but still no luck. Any idea?