Search code examples
qtqt4fullscreenqglwidget

How to show QGLWidget in full screen?


I have a QGLWidget as part of the UI of my application. It is NOT a central widget, there are a lot of others widgets around it. I want to show it full screen on user clicks the button. Similar functionality like on youtube video flash player.

I have tried to use showFullScreen with no effect.

I have read how-to-fullscreen-a-qglwidget and fullscreen-widget, but they suggest using showFullScreen.

Qt documentation states that for using showFullScreen widget must be an independent window. So I assume there should be some trick for this.


Solution

  • The solution I found:

    void MyApp::on_fullscreen_button_clicked() {
        QDialog *dlg = new QDialog(this);
        QHBoxLayout *dlg_layout = new QHBoxLayout(dlg);
        dlg_layout->setContentsMargins(0, 0, 0, 0);
        dlg_layout->addWidget(glwidget_);
        dlg->setLayout(dlg_layout);
        dlg->showFullScreen();
    
        bool r = connect(dlg, SIGNAL(rejected()), this, SLOT(showGlNormal()));
        assert(r);
        r = connect(dlg, SIGNAL(accepted()), this, SLOT(showGlNormal()));
        assert(r);
    }
    
    void MyApp::showGlNormal() {
        ui.glBox->layout()->addWidget(glwidget_);
    }