How to show QGLWidget in full screen?

假装没事ソ 提交于 2019-12-11 10:34:04

问题


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.


回答1:


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_);
}



回答2:


The showFullScreen function works only on windows. From the Qt documentation:

A window is a widget that isn't visually the child of any other widget and that usually has a frame and a window title.

A possible solution is the following:

When the user clicks the show full screen button

  • Create a new QGlWidget with no parent and set to it the contents of you QGlWidget
  • Use the showFullScreen function on it...

Maybe it is a better idea to subclass QGlWidget and pass in its constructor a pointer to another QGlWidget. The constructor should take the context of the provided widget and apply it to the new one.

  • On your subclass catch keyboard events. When the user press Esc emit a signal
  • In your base class catch this signal and connect it to a slot. In this slot hide the full screen QGlWidget and delete it.


来源:https://stackoverflow.com/questions/8008526/how-to-show-qglwidget-in-full-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!