本文介绍了如何全屏显示QGLWidget?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个QGLWidget作为应用程序UI的一部分.它不是不是中央小部件,周围还有许多其他小部件.我想在用户单击按钮时全屏显示它.类似于youtube video Flash Player上的功能.

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.

我尝试使用 showFullScreen 无效.

我已阅读 how-to-fullscreen-a-qglwidget fullscreen-widget ,但他们建议使用showFullScreen.

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

Qt文档指出,使用showFullScreen小部件必须是一个独立的窗口.因此,我认为应该有一些技巧.

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

推荐答案

我找到的解决方案:

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

这篇关于如何全屏显示QGLWidget?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 19:38