QVideoWidget::setFullScreen(true) is not working properly first time when added QVideoWidget in QStackedLayout
-
Hi,
Here is my code in which QVideoWidget::setFullScreen(true) is not showing videoWdiget in fullscreen when added in QStackedLayout:QStackedLayout *stackedLayout = new QStackedLayout;
stackedLayout->addWidget(m_videoWidget);
stackedLayout->setCurrentIndex(0);QBoxLayout *mainLayout = new QVBoxLayout; mainLayout->addLayout(stackedLayout, 1); setLayout(mainLayout);
- When video start playing, I am setting videoWdiget to fullscreen
void MediaPlayer::playbackStateChanged(QMediaPlayer::PlaybackState state)
{
//qDebug() << QString("MediaPlayer::playbackStateChanged state=%1").arg(state);
switch (state) {case QMediaPlayer::PlayingState: m_videoWidget->setFullScreen(true); break; }
}
although m_videoWidget->isFullScreen is true, but window is not fullscreen. When I clicked my 'FullScreen' button again, it will set to m_videoWidget->isFullScreen to false and when I press 'FullScreen' button again, then it will show videoWidget as fullScreen.
My observation is it required user interaction and then QVideoWidget::setFullScreen working fine. Any hint what is missing here?
================Previous code - which was working fine
Earlier I have this code in which videoWidget is displaying as fullScreen, but I have to use QStackedLayout so that I can switch between ImageViewer and QVideoWidget based on image/video media file type.void MediaPlayer::setPlayerLayout_old()
{
try {
QBoxLayout *displayLayout = new QHBoxLayout;
displayLayout->addWidget(m_videoWidget, 1);QBoxLayout *mainLayout = new QVBoxLayout; mainLayout->addLayout(displayLayout, 1); setLayout(mainLayout); if (!isPlayerAvailable()) { QMessageBox::warning(this, tr("Service not available"), tr("The QMediaPlayer object does not have a valid service.\n"\ "Please check the media service plugins are installed.")); } } catch (...) { qCritical() << "MediaPlayer::setPlayerLayout: Exception occured. "; }
}
Thanks in advance for your help!
-
@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.