当 QGLWidget 是其他窗口的父级时,将 QGLWidget 全屏显示

发布于 2024-12-01 18:35:49 字数 244 浏览 1 评论 0原文

我已成功通过调用 QGLWidget 的 showFullScreen() 和 showNormal() 来打开/关闭全屏,该 QGLWidget 是我的 Qt 应用程序的顶级窗口。但是,我希望有一个从 QGLWidget 派生的 gl 窗口作为更复杂 GUI 的一部分,其父窗口是另一个包含其他小部件(包括另一个 glwidget)的主窗口,并且让这个“主”gl 窗口能够全屏显示并通过按键返回。我无法找到说明如何执行此操作的文档,有什么帮助吗?

谢谢!!

I have managed to turn fullscreen on/off by calling showFullScreen() and showNormal() for a QGLWidget that is the top level window of my Qt App. However, I would like to have a gl window derived from QGLWidget as part of a more complex GUI, parented to another mainwindow with other widgets in it(including another glwidget), and have this "primary" gl window be able to go fullscreen and back with a keystroke. I have not been able to find documentation showing me how to do this, any help?

Thanks!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

写给空气的情书 2024-12-08 18:35:49

基本上,您需要有一种方法让嵌套的 QGLWidget 或其父级使用 QGLWidget 的另一个实例调用 showFullScreen() 。然后就有办法回去了。

要通过按键或单击鼠标来完成此操作,您需要为所有小部件重新实现 QKeyEvent 和 QMouseEvent,当您希望全屏显示和全屏隐藏作为可用选项时,这些小部件将具有焦点。

因此,根据您弹出并与 GUI 的 QMainWindow 部分分开显示的窗口数量,您可能希望其他窗口也支持按键来隐藏/显示全屏 QGLWidget。

下面是我一次执行此操作的代码片段,但仅限于鼠标交互:

void MyWidget::enterEvent(QEvent *)
{
    if(this->isFullScreen())
    {
        textItem->setText("Click again to return");
    }
    else
        textItem->setText("Click for full screen");

    //      if(!clearTextTimer->isActive())
    //          clearTextTimer->start();
    clearTextTimer->start();
    this->update();
}

void MyWidget::mouseReleaseEvent(QMouseEvent *event)
{
    static MyWidget * w = 0;
    if(pixItem->contains(mapToScene(event->pos()))
            && event->button() != Qt::NoButton
            && w == 0)
    {
        w = new MyWidget();
        w->showFullScreen();
    }
    else
    {
        if(this->isMaximized())
            this->close();
        else
            w->close();
        delete w;
        w = 0;
    }
}

您还需要查看grabKeyboard() 和releaseKeyboard()。

Basically, you will need to have a way for the nested QGLWidget or it's parent to call showFullScreen() with another instance of your QGLWidget. Then have a way to go back.

To do this with a key press or a mouse click you need to reimplement QKeyEvent and QMouseEvent for all widgets that will have the focus when you want the fullscreen show and the fullscreen hide as an available option.

So depending on how many windows you are popping up and showing separately from your QMainWindow part of your GUI, you may want to have other windows also support a key press that will do the hide/show your fullscreen QGLWidget.

Here is a code snippet of how I did it once, but only with mouse interactions:

void MyWidget::enterEvent(QEvent *)
{
    if(this->isFullScreen())
    {
        textItem->setText("Click again to return");
    }
    else
        textItem->setText("Click for full screen");

    //      if(!clearTextTimer->isActive())
    //          clearTextTimer->start();
    clearTextTimer->start();
    this->update();
}

void MyWidget::mouseReleaseEvent(QMouseEvent *event)
{
    static MyWidget * w = 0;
    if(pixItem->contains(mapToScene(event->pos()))
            && event->button() != Qt::NoButton
            && w == 0)
    {
        w = new MyWidget();
        w->showFullScreen();
    }
    else
    {
        if(this->isMaximized())
            this->close();
        else
            w->close();
        delete w;
        w = 0;
    }
}

You will also want to look at grabKeyboard() and releaseKeyboard().

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文