C++ 如何设置 QWidget 全屏(但“真正的”全屏,更改分辨率,将模式设置为整个系统)?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9412971/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 12:47:46  来源:igfitidea点击:

How to set QWidget fullscreen (but "real" fullscreen, change resolution, set modal to whole system)?

c++qtfullscreenresolutionqwidget

提问by neciu

I'm trying to make a game using Qt, cause it is so awesome ;) and you have all the stuff you need for free. The only problem is in changing system resolution and setting QWidget (or QGLWidget) "real" fullscreen.

我正在尝试使用 Qt 制作游戏,因为它太棒了 ;) 而且您拥有免费所需的所有东西。唯一的问题是更改系统分辨率和设置 QWidget(或 QGLWidget)“真实”全屏。

Have any one of you managed to do something like this? How was the portability of such approach? I'd like to deploy my app on all desktop systems.

你们中有人设法做这样的事情吗?这种方法的可移植性如何?我想在所有桌面系统上部署我的应用程序。

Maybe use SDL or something like SMFL to make it fullscreen?

也许使用 SDL 或类似 SMFL 的东西使其全屏?

Pls, share your hacks!

请分享您的技巧!

Cheers.

干杯。

回答by Exa

This...

这个...

my_widget->setWindowState(Qt::WindowFullScreen);

... brings your widget to a full screen resolution. Isn't that what you need?

...使您的小部件达到全屏分辨率。这不是你需要的吗?

Edit:Alternatively you can call the slot showFullScreen.

编辑:或者,您可以调用插槽showFullScreen

Edit 2:

编辑2:

  1. WIN API
    1. EnumDisplaySettings
    2. ChangeDisplaySettings
    3. Detailed information
  2. X11
    1. I'm not familiar with this, you could ask a new question regarding how to change the screen resolution here
  3. Mac
    1. Same as X11
  1. 赢取API
    1. 枚举显示设置
    2. 更改显示设置
    3. 详细资料
  2. X11
    1. 我对此不熟悉,您可以在此处提出有关如何更改屏幕分辨率的新问题
  3. 苹果电脑
    1. 与X11相同

回答by Neox

First you have to set corresponding window flags to make your widget modal, and also get rid of the window manager frame so it will be true fullscreen

首先,您必须设置相应的窗口标志以使您的小部件模态化,并摆脱窗口管理器框架,使其成为真正的全屏

widget->setWindowFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint);

widget->setWindowFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint);

and after that call widget->showFullScreen();as Exa said.

在那次电话之后,widget->showFullScreen();正如 Exa 所说。

回答by gutek

Fullscreen:

全屏:

topwidget->setWindowState(topwidget->windowState() ^ Qt::Window);