QVideoWidget is set to QMainWindow. I open the video file, start the playback, everything works fine, I watch the video on the form. Then I press the fullscreen button, which calls m_videoWgt-> setfullScreen (true) the video unfolds to full screen and everything is fine too. But when I exit full screen mode, my form shows nothing. Here is an example:

#include "mainwindow.h" #include "ui_mainwindow.h" #include <QMediaPlayer> #include <QVideoWidget> #include <QFileDialog> #include <QKeyEvent> #include <QVBoxLayout> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), m_player(new QMediaPlayer(this)) { m_videoWgt = new VideoWidget; /*m_videoWgt->resize(200, 200); m_videoWgt->show(); */ ui->setupUi(this); m_player->setVideoOutput(m_videoWgt); /*m_videoWgt->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); m_videoWgt->setAttribute(Qt::WA_OpaquePaintEvent); */ QVBoxLayout * lt = new QVBoxLayout; lt->addWidget(m_videoWgt); ui->centralWidget->setLayout(lt); connect(m_videoWgt, SIGNAL(fullScreenChanged(bool)), ui->centralWidget, SLOT(repaint())); } MainWindow::~MainWindow() { delete ui; } void MainWindow::on_actionFull_Screen_triggered() { m_videoWgt->setFullScreen(!m_videoWgt->isFullScreen()); } void MainWindow::on_actionOpen_triggered() { QString path = QFileDialog::getOpenFileName(); if (path.isEmpty()) return; m_player->setMedia(QMediaContent(QUrl::fromLocalFile(path))); } void MainWindow::on_actionPlay_triggered() { m_player->play(); } void MainWindow::on_actionStop_triggered() { m_player->stop(); } VideoWidget::VideoWidget(QWidget *parent) { } void VideoWidget::keyPressEvent(QKeyEvent *event) { setFullScreen(false); } 

Here is the * .h file:

 #ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> class QMediaPlayer; #include <QVideoWidget> class VideoWidget : public QVideoWidget { Q_OBJECT public: explicit VideoWidget(QWidget * parent = 0); protected: void keyPressEvent(QKeyEvent *event); }; namespace Ui { class MainWindow; } class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); private slots: void on_actionFull_Screen_triggered(); void on_actionOpen_triggered(); void on_actionPlay_triggered(); void on_actionStop_triggered(); private: Ui::MainWindow *ui; QMediaPlayer * m_player; VideoWidget * m_videoWgt; }; #endif // MAINWINDOW_H 

Can you tell me what the problem is? I tried it differently: I do not install QVideoWidget in the mainwindow, but leave it free, in the form of a separate widget. Then everything works well after exiting full-screen mode. Hence the conclusion that maybe we need to hook on the QVideoWidget signal fullScreenChanged (bool) and do something in the mainwindow. Any ideas?

  • On Windows this is not observed. - nicolai

1 answer 1

Maybe someone will help, guys, this is a Qtshny bug, used QGraphicsScene, it works very well.