QGuiApplication 类管理 GUI 应用程序的控制流和主要设置。 更多...
头: | #include <QGuiApplication> |
CMake: |
find_package(Qt6 REQUIRED COMPONENTS Gui)
target_link_libraries(mytarget PRIVATE Qt6::Gui) |
qmake: | QT += gui |
继承: | QCoreApplication |
继承者: | QApplication |
|
|
QGuiApplication (int & argc , char ** argv ) | |
virtual | ~QGuiApplication () |
qreal | devicePixelRatio () const |
bool | isSavingSession () const |
bool | isSessionRestored () const |
QNativeInterface * | nativeInterface () const |
QString | sessionId () const |
QString | sessionKey () const |
virtual bool | notify (QObject * object , QEvent * event ) override |
void | setBadgeNumber (qint64 number ) |
void | applicationDisplayNameChanged () |
void | applicationStateChanged (Qt::ApplicationState state ) |
void | commitDataRequest (QSessionManager & manager ) |
void | focusObjectChanged (QObject * focusObject ) |
void | focusWindowChanged (QWindow * focusWindow ) |
void | fontDatabaseChanged () |
void | lastWindowClosed () |
void | layoutDirectionChanged (Qt::LayoutDirection direction ) |
void | primaryScreenChanged (QScreen * screen ) |
void | saveStateRequest (QSessionManager & manager ) |
void | screenAdded (QScreen * screen ) |
void | screenRemoved (QScreen * screen ) |
QWindowList | allWindows () |
QString | applicationDisplayName () |
Qt::ApplicationState | applicationState () |
void | changeOverrideCursor (const QCursor & cursor ) |
QClipboard * | clipboard () |
QString | desktopFileName () |
bool | desktopSettingsAware () |
int | exec () |
QObject * | focusObject () |
QWindow * | focusWindow () |
QFont | font () |
Qt::HighDpiScaleFactorRoundingPolicy | highDpiScaleFactorRoundingPolicy () |
QInputMethod * | inputMethod () |
bool | isLeftToRight () |
bool | isRightToLeft () |
Qt::KeyboardModifiers | keyboardModifiers () |
Qt::LayoutDirection | layoutDirection () |
QWindow * | modalWindow () |
Qt::MouseButtons | mouseButtons () |
QCursor * | overrideCursor () |
QPalette | palette () |
QString | platformName () |
QScreen * | primaryScreen () |
Qt::KeyboardModifiers | queryKeyboardModifiers () |
bool | quitOnLastWindowClosed () |
void | restoreOverrideCursor () |
QScreen * | screenAt (const QPoint & point ) |
QList<QScreen *> | screens () |
void | setApplicationDisplayName (const QString & name ) |
void | setDesktopFileName (const QString & name ) |
void | setDesktopSettingsAware (bool on ) |
void | setFont (const QFont & font ) |
void | setHighDpiScaleFactorRoundingPolicy (Qt::HighDpiScaleFactorRoundingPolicy policy ) |
void | setLayoutDirection (Qt::LayoutDirection direction ) |
void | setOverrideCursor (const QCursor & cursor ) |
void | setPalette (const QPalette & pal ) |
void | setQuitOnLastWindowClosed (bool quit ) |
void | setWindowIcon (const QIcon & icon ) |
QStyleHints * | styleHints () |
void | sync () |
QWindow * | topLevelAt (const QPoint & pos ) |
QWindowList | topLevelWindows () |
QIcon | windowIcon () |
virtual bool | event (QEvent * e ) override |
qGuiApp |
QGuiApplication 包含主事件循环,处理和分派来自窗口系统和其它源的所有事件。它还处理应用程序的初始化和定稿,及提供会话管理。此外,QGuiApplication 处理大多数系统范围和应用程序范围的设置。
对于使用 QT 的任何 GUI 应用程序,准确存在 one QGuiApplication 对象,无论应用程序在任何给定时间是否拥有 0 个、1 个、2 个或更多个窗口。对于非 GUI Qt 应用程序,使用 QCoreApplication 代替,因为它不依赖 Qt GUI 模块。对于 QWidget 基 Qt 应用程序,使用 QApplication 代替,因为由它提供的某些功能需要创建 QWidget 实例。
QGuiApplication 对象可访问透过 instance () 函数,返回指针相当于全局 qApp 指针。
QApplication 主要负责的领域:
由于 QGuiApplication 对象会做如此多的初始化,它
must
被创建,在创建用户界面相关的任何其它对象之前。QGuiApplication 还处理常见命令行自变量。因此,创建它通常是一个好主意
before
任何解释或修改对于
argv
的履行在应用程序本身。
函数组 | |
---|---|
系统设置 | desktopSettingsAware (), setDesktopSettingsAware (), styleHints (), palette (), setPalette (), font (), setFont (). |
事件处理 | exec (), processEvents (), exit (), quit (). sendEvent (), postEvent (), sendPostedEvents (), removePostedEvents (), notify (). |
Windows | allWindows (), topLevelWindows (), focusWindow (), clipboard (), topLevelAt (). |
高级光标处理 | overrideCursor (), setOverrideCursor (), restoreOverrideCursor (). |
会话管理 | isSessionRestored (), sessionId (), commitDataRequest (), saveStateRequest (). |
杂项 | startingUp (), closingDown (). |
另请参阅 QCoreApplication , QAbstractEventDispatcher ,和 QEventLoop .
此特性保持此应用程序的用户可见名称
此名称将展示给用户,例如在窗口标题中。 可以翻译它,若有必要。
若未设置,应用程序显示名称默认为应用程序名称。
访问函数:
QString | applicationDisplayName () |
void | setApplicationDisplayName (const QString & name ) |
通知程序信号:
void | applicationDisplayNameChanged () |
另请参阅 applicationName .
此特性保持用于此应用程序桌面条目的基本名称
This is the file name, without the full path or the trailing ".desktop" extension of the desktop entry that represents this application according to the freedesktop desktop entry specification.
此特性给出什么桌面条目表示应用程序的精密指示,且窗口系统需要在不求助于不精密试探的情况下检索这种信息。
可以获得最新版本的 freedesktop 桌面条目规范 here .
访问函数:
QString | desktopFileName () |
void | setDesktopFileName (const QString & name ) |
此特性保持用于此应用程序的默认布局方向
On system start-up, or when the direction is explicitly set to Qt::LayoutDirectionAuto , the default layout direction depends on the application's language.
通知信号在 Qt 5.4 引入。
访问函数:
Qt::LayoutDirection | layoutDirection () |
void | setLayoutDirection (Qt::LayoutDirection direction ) |
通知程序信号:
void | layoutDirectionChanged (Qt::LayoutDirection direction ) |
另请参阅 QWidget::layoutDirection , isLeftToRight (),和 isRightToLeft ().
[read-only]
platformName
: const
QString
此特性保持底层平台插件的名称。
QPA 平台插件位于
qtbase\src\plugins\platforms
。当撰写本文时,支持下列平台插件名称:
android
cocoa
是 macOS 平台插件。
directfb
eglfs
是无需实际窗口系统 (像 X11 或 Wayland) 在 EGL 和 OpenGL ES 2.0 之上运行 Qt5 应用程序的平台插件。更多信息,见
EGLFS
.
ios
(还用于 tvOS)
linuxfb
直接写入帧缓冲。更多信息,见
LinuxFB
.
minimal
为想要编写自己平台插件的开发者提供范例。不管怎样,可以使用插件在没有 GUI 的环境下运行 GUI 应用程序,譬如:服务器。
minimalegl
是范例插件。
offscreen
qnx
windows
wayland
is a platform plugin for the Wayland display server protocol, used on some Linux desktops and embedded systems.
xcb
is a plugin for the X11 window system, used on some desktop Linux platforms.
关于嵌入式 Linux 设备平台插件的更多信息,见 Qt for Embedded Linux .
访问函数:
QString | platformName () |
[read-only]
primaryScreen
:
QScreen
* const
此特性保持应用程序的首要 (或默认) 屏幕。
这将是最初展示 QWindows 的屏幕,除非另有指定。
primaryScreenChanged 信号在 Qt 5.6 引入。
访问函数:
QScreen * | primaryScreen () |
通知程序信号:
void | primaryScreenChanged (QScreen * screen ) |
另请参阅 screens ().
此特性保持应用程序是否隐式离开,当关闭最后一个窗口时。
默认为
true
.
若此特性为
true
,应用程序离开当最后一个可见
首要窗口
(即:没有瞬时父级的顶层窗口) 被关闭。
访问函数:
bool | quitOnLastWindowClosed () |
void | setQuitOnLastWindowClosed (bool quit ) |
另请参阅 quit () 和 QWindow::close ().
此特性保持默认窗口图标
访问函数:
QIcon | windowIcon () |
void | setWindowIcon (const QIcon & icon ) |
另请参阅 QWindow::setIcon () 和 设置应用程序图标 .
初始化窗口系统并构造应用程序对象采用 argc 命令行自变量在 argv .
警告: 数据引用通过 argc and argv must stay valid for the entire lifetime of the QGuiApplication object. In addition, argc 必须大于 0 且 argv 必须包含至少一有效字符串。
全局
qApp
指针引用此应用程序对象。只应创建一个应用程序对象。
此应用程序对象必须被构造先于任何 描绘设备 (包括像素图、位图等)。
注意: argc and argv 可能改变当 Qt 移除它识别的命令行自变量时。
所有 Qt 程序自动支持允许修改 Qt 与窗口系统交互方式的一组命令行选项。首选凭借环境变量访问某些选项,若应用程序可以发起 GUI 子进程或其它应用程序 (环境变量将由子级进程继承)。当有疑问时,使用环境变量。
目前支持下列选项:
-platform
platformName
[:options]
,指定
Qt Platform Abstraction
(QPA) 插件。
覆写
QT_QPA_PLATFORM
环境变量。
-platformpluginpath
path
,指定平台插件的路径。
覆写
QT_QPA_PLATFORM_PLUGIN_PATH
环境变量。
-platformtheme
platformTheme
,指定平台主题。
覆写
QT_QPA_PLATFORMTHEME
环境变量。
-plugin
plugin
,指定要加载的额外插件。自变量可能出现多次。
Concatenated with the plugins in the
QT_QPA_GENERIC_PLUGINS
环境变量。
-qmljsdebugger=
,采用指定端口激活 QML/JS 调试器。值格式必须为
port:1234
[,block]
,其中
block
可选且将使应用程序等待,直到调试器连接到它为止。
-qwindowgeometry
geometry
,使用 X11 句法为主窗口指定窗口几何体。例如:
-qwindowgeometry 100x100+50+50
-qwindowicon
,设置默认窗口图标
-qwindowtitle
,设置第一窗口标题
-reverse
,将应用程序的布局方向设为
Qt::RightToLeft
。此选项旨在辅助调试且不应用于生产。默认值自动检测自用户区域设置 (另请参阅
QLocale::textDirection
()).
-session
session
,还原应用程序从早期
session
.
下列标准命令行选项可用于 X11:
-display
hostname:screen_number
,切换 X11 显示。
覆写
DISPLAY
环境变量。
-geometry
geometry
,如同
-qwindowgeometry
.
可以指定特定平台自变量为
-platform
选项。 将它们放在平台插件名称后,随后冒号紧跟逗号分隔列表。例如,
-platform windows:dialogs=xp,fontengine=freetype
.
以下参数可用于
-platform windows
:
altgr
, detect the key
AltGr
found on some keyboards as
Qt::GroupSwitchModifier
(since Qt 5.12).
darkmode=[0|1|2]
controls how Qt responds to the activation of the
Dark Mode for applications
introduced in Windows 10 1903 (since Qt 5.15).
A value of 0 disables dark mode support.
A value of 1 causes Qt to switch the window borders to black when Dark Mode for applications is activated and no High Contrast Theme is in use. This is intended for applications that implement their own theming.
A value of 2 will in addition cause the Windows Vista style to be deactivated and switch to the Windows style using a simplified palette in dark mode. This is currently experimental pending the introduction of new style that properly adapts to dark mode.
As of Qt 6.5, the default value is 2; to disable dark mode support, set the value to 0 or 1.
dialogs=[xp|none]
,
xp
使用 XP 风格本机对话框和
none
禁用它们。
fontengine=freetype
, uses the FreeType font engine.
fontengine=directwrite
, uses the experimental DirectWrite font database and defaults to using the DirectWrite font engine (which is otherwise only used for some font types or font properties.) This affects font selection and aims to provide font naming more consistent with other platforms, but does not support all font formats, such as Postscript Type-1 or Microsoft FNT fonts.
menus=[native|none]
, controls the use of native menus.
Native menus are implemented using Win32 API and are simpler than QMenu -based menus in for example that they do allow for placing widgets on them or changing properties like fonts and do not provide hover signals. They are mainly intended for Qt Quick. By default, they will be used if the application is not an instance of QApplication or for Qt Quick Controls 2 applications (since Qt 5.10).
nocolorfonts
Turn off DirectWrite Color fonts (since Qt 5.8).
nodirectwrite
Turn off DirectWrite fonts (since Qt 5.8).
nomousefromtouch
Ignores mouse events synthesized from touch events by the operating system.
nowmpointer
Switches from Pointer Input Messages handling to legacy mouse handling (since Qt 5.12).
reverse
Activates Right-to-left mode (experimental). Windows title bars will be shown accordingly in Right-to-left locales (since Qt 5.13).
tabletabsoluterange=<value>
Sets a value for mouse mode detection of WinTab tablets (Legacy, since Qt 5.3).
The following parameter is available for
-platform cocoa
(on macOS):
fontengine=freetype
, uses the FreeType font engine.
关于可用于嵌入式 Linux 平台的特定平台自变量的更多信息,见 Qt for Embedded Linux .
另请参阅 arguments () 和 QGuiApplication::platformName .
[virtual]
QGuiApplication::
~QGuiApplication
()
销毁应用程序。
[static]
QWindowList
QGuiApplication::
allWindows
()
返回应用程序所有窗口的列表。
列表为空,若没有窗口。
另请参阅 topLevelWindows ().
[static]
Qt::ApplicationState
QGuiApplication::
applicationState
()
返回应用程序的当前状态。
可以对应用程序状态改变做出反应,以履行譬如:停止/再继续 CPU 密集型任务、释放/加载资源、或保存/还原应用程序数据。
[signal]
void
QGuiApplication::
applicationStateChanged
(
Qt::ApplicationState
state
)
此信号被发射当 state 对于应用程序改变。
另请参阅 applicationState ().
[static]
void
QGuiApplication::
changeOverrideCursor
(const
QCursor
&
cursor
)
将当前活动应用程序的覆盖光标改为 cursor .
此函数不起作用若 setOverrideCursor () 未被调用。
另请参阅 setOverrideCursor (), overrideCursor (), restoreOverrideCursor (),和 QWidget::setCursor ().
[static]
QClipboard
*QGuiApplication::
clipboard
()
返回与剪贴板交互的对象。
[signal]
void
QGuiApplication::
commitDataRequest
(
QSessionManager
&
manager
)
此信号处理 会话管理 。它被发射当 QSessionManager 想要应用程序提交其所有数据。
通常这意味着保存所有打开文件,在从用户获得权限后。此外,可能想要提供由用户可以取消关闭的手段。
不应退出应用程序,在此信号内。相反,会话管理器可以 (或不可以) 之后这样做,从属上下文。
警告: 在此信号内,不可能进行用户交互, unless 要求 manager 明确权限。见 QSessionManager::allowsInteraction () 和 QSessionManager::allowsErrorInteraction () 了解细节和范例用法。
注意: 应使用 Qt::DirectConnection 当连接到此信号时。
另请参阅 isSessionRestored (), sessionId (), saveStateRequest (),和 会话管理 .
[static]
bool
QGuiApplication::
desktopSettingsAware
()
返回
true
若 Qt 被设为使用系统标准颜色、字体、等;否则返回
false
。默认为
true
.
另请参阅 setDesktopSettingsAware ().
返回系统中找到的最高屏幕设备像素比率。这是物理像素和设备无关像素之间的比率。
才使用此函数,当不知道目标窗口是哪个时。若知道目标窗口,使用 QWindow::devicePixelRatio () 代替。
另请参阅 QWindow::devicePixelRatio ().
[override virtual protected]
bool
QGuiApplication::
event
(
QEvent
*
e
)
重实现: QCoreApplication::event (QEvent *e).
[static]
int
QGuiApplication::
exec
()
进入主事件循环并等待,直到 exit () 被调用,然后将设置值返回给 exit () (为 0 若 exit () 被调用凭借 quit ()).
有必要调用此函数以启动事件处理。主事件循环从窗口系统接收事件,并将其分派给应用程序 Widget。
一般来说,不可以进行用户交互在调用 exec() 之前。
要使应用程序履行空闲处理 (如:执行特殊函数每当没有待处理事件时),使用 QTimer 采用 0 超时。更高级空闲处理方案可以达成使用 processEvents ().
推荐把清理代码连接到
aboutToQuit
() 信号,而不是将它放入应用程序的
main()
函数。这是因为,在某些平台,
QApplication::exec
() 调用可能不返回。
另请参阅 quitOnLastWindowClosed , quit (), exit (), processEvents (),和 QCoreApplication::exec ().
[static]
QObject
*QGuiApplication::
focusObject
()
返回 QObject 在当前活动窗口,将是聚焦捆绑事件 (譬如:键事件) 的最终接收者。
[signal]
void
QGuiApplication::
focusObjectChanged
(
QObject
*
focusObject
)
此信号被发射,当聚焦捆绑事件的最终接收者改变时。 focusObject 是新接收者。
另请参阅 focusObject ().
[static]
QWindow
*QGuiApplication::
focusWindow
()
返回 QWindow 接收聚焦捆绑事件,譬如:键事件。
另请参阅 QWindow::requestActivate ().
[signal]
void
QGuiApplication::
focusWindowChanged
(
QWindow
*
focusWindow
)
此信号被发射,当聚焦窗口改变时。 focusWindow 是新聚焦窗口。
另请参阅 focusWindow ().
[static]
QFont
QGuiApplication::
font
()
返回应用程序的默认字体。
另请参阅 setFont ().
[signal]
void
QGuiApplication::
fontDatabaseChanged
()
This signal is emitted when the available fonts have changed.
This can happen when application fonts are added or removed, or when the system fonts change.
另请参阅 QFontDatabase::addApplicationFont (), QFontDatabase::addApplicationFontFromData (), QFontDatabase::removeAllApplicationFonts (),和 QFontDatabase::removeApplicationFont ().
[static]
Qt::HighDpiScaleFactorRoundingPolicy
QGuiApplication::
highDpiScaleFactorRoundingPolicy
()
返回高 DPI (每英寸点数) 比例缩放因子舍入策略。
另请参阅 setHighDpiScaleFactorRoundingPolicy ().
[static]
QInputMethod
*QGuiApplication::
inputMethod
()
返回输入法。
输入法返回虚拟键盘状态和位置的有关特性。它还提供当前聚焦输入元素位置的有关信息。
另请参阅 QInputMethod .
[static]
bool
QGuiApplication::
isLeftToRight
()
返回
true
若应用程序的布局方向是
Qt::LeftToRight
;否则返回
false
.
另请参阅 layoutDirection () 和 isRightToLeft ().
[static]
bool
QGuiApplication::
isRightToLeft
()
返回
true
若应用程序的布局方向是
Qt::RightToLeft
;否则返回
false
.
另请参阅 layoutDirection () 和 isLeftToRight ().
返回
true
若应用程序目前正在保存
session
;否则返回
false
.
这为
true
当
commitDataRequest
() 和
saveStateRequest
() 被发射,且之后通过会话管理关闭窗口时也如此。
另请参阅 sessionId (), commitDataRequest (),和 saveStateRequest ().
返回
true
若应用程序已还原从较早
session
;否则返回
false
.
另请参阅 sessionId (), commitDataRequest (),和 saveStateRequest ().
[static]
Qt::KeyboardModifiers
QGuiApplication::
keyboardModifiers
()
Returns the current state of the modifier keys on the keyboard. The current state is updated synchronously as the event queue is emptied of events that will spontaneously change the keyboard state ( QEvent::KeyPress and QEvent::KeyRelease 事件)。
应注意,这可能不反映调用时在输入设备上保持的实际键,但反映上述事件之一最后报告的修饰符。若没有保持键, Qt::NoModifier 被返回。
另请参阅 mouseButtons () 和 queryKeyboardModifiers ().
[signal]
void
QGuiApplication::
lastWindowClosed
()
此信号被发射从 exec () 当最后一个可见 首要窗口 (即:没有瞬时父级的顶层窗口) 被关闭。
默认情况下,
QGuiApplication
离开在此信号被发射之后。可以关闭此特征通过设置
quitOnLastWindowClosed
to
false
.
另请参阅 QWindow::close (), QWindow::isTopLevel (),和 QWindow::transientParent ().
[static]
QWindow
*QGuiApplication::
modalWindow
()
返回最近展示的模态窗口。若没有可见的模态窗口,此函数返回 0。
模态窗口这种窗口有它自己的 modality 特性被设为 Qt::WindowModal or Qt::ApplicationModal 。必须关闭模态窗口,在用户可以继续使用程序其它部分前。
模态窗口被组织在堆栈中。此函数返回在堆栈顶部的模态窗口。
另请参阅 Qt::WindowModality and QWindow::setModality ().
[static]
Qt::MouseButtons
QGuiApplication::
mouseButtons
()
Returns the current state of the buttons on the mouse. The current state is updated synchronously as the event queue is emptied of events that will spontaneously change the mouse state ( QEvent::MouseButtonPress and QEvent::MouseButtonRelease 事件)。
应该注意,这可能不反映调用时在输入设备中保持的实际按钮,而是上述事件之一最后报告的鼠标按钮。若未按住鼠标按钮 Qt::NoButton 被返回。
另请参阅 keyboardModifiers ().
Returns a native interface of the given type for the application.
This function provides access to platform specific functionality of QGuiApplication , as defined in the QNativeInterface 名称空间:
QNativeInterface::QWaylandApplication | Native interface to a Wayland application |
QNativeInterface::QX11Application | 到 X11 应用程序的本机接口 |
If the requested interface is not available a
nullptr
被返回。
[override virtual]
bool
QGuiApplication::
notify
(
QObject
*
object
,
QEvent
*
event
)
重实现: QCoreApplication::notify (QObject *receiver, QEvent *event).
[static]
QCursor
*QGuiApplication::
overrideCursor
()
返回活动应用程序的覆盖光标。
此函数返回
nullptr
若应用程序光标未定义 (即:内部光标堆栈为空)。
另请参阅 setOverrideCursor () 和 restoreOverrideCursor ().
[static]
QPalette
QGuiApplication::
palette
()
返回当前应用程序调色板。
尚未明确设置的角色,将反射系统平台主题。
另请参阅 setPalette ().
[static]
Qt::KeyboardModifiers
QGuiApplication::
queryKeyboardModifiers
()
查询并返回键盘修饰符键的状态。不像 keyboardModifiers 此方法返回调用方法时保持在输入设备上的实际键。
它不依赖必须由此进程接收的键按下事件,譬如:这使得当移动窗口时校验修饰符成为可能。注意:在大多数情况下,应使用 keyboardModifiers (),其更快更准确,因为它包含的修饰符状态 (如同接收当前处理事件时状态)。
另请参阅 keyboardModifiers ().
[static]
void
QGuiApplication::
restoreOverrideCursor
()
撤消最后 setOverrideCursor ().
若 setOverrideCursor () 被调用 2 次,调用 restoreOverrideCursor() 将激活第 1 次光标设置。第 2 次调用此函数将还原 Widget 的原始光标。
另请参阅 setOverrideCursor () 和 overrideCursor ().
[signal]
void
QGuiApplication::
saveStateRequest
(
QSessionManager
&
manager
)
此信号处理 会话管理 。它被援引当 会话管理器 想要应用程序为未来会话保留其状态。
例如,文本编辑器将创建临时文件 (包括当前编辑缓冲内容、光标位置及当前编辑会话的其它方面)。
You should never exit the application within this signal. Instead, the session manager may or may not do this afterwards, depending on the context. Furthermore, most session managers will very likely request a saved state immediately after the application has been started. This permits the session manager to learn about the application's restart policy.
警告: 在此信号内,不可能进行用户交互, unless 要求 manager 明确权限。见 QSessionManager::allowsInteraction () 和 QSessionManager::allowsErrorInteraction () 了解细节。
注意: 应使用 Qt::DirectConnection 当连接到此信号时。
另请参阅 isSessionRestored (), sessionId (), commitDataRequest (),和 会话管理 .
[signal]
void
QGuiApplication::
screenAdded
(
QScreen
*
screen
)
此信号被发射每当新屏幕 screen 已添加到系统。
另请参阅 screens (), primaryScreen ,和 screenRemoved ().
[static]
QScreen
*QGuiApplication::
screenAt
(const
QPoint
&
point
)
返回屏幕,位于
point
,或
nullptr
若在任何屏幕之外。
The
point
is in relation to the virtualGeometry() of each set of virtual siblings. If the point maps to more than one set of virtual siblings the first match is returned. If you wish to search only the virtual desktop siblings of a known screen (for example siblings of the screen of your application window
QWidget::windowHandle()->screen()
), use
QScreen::virtualSiblingAt
().
[signal]
void
QGuiApplication::
screenRemoved
(
QScreen
*
screen
)
此信号被发射每当 screen 被移除从系统。它提供了管理屏幕窗口的机会,在 Qt 回退以将它们移到首要屏幕之前。
另请参阅 screens (), screenAdded (), QObject::destroyed (),和 QWindow::setScreen ().
[static]
QList
<
QScreen
*> QGuiApplication::
screens
()
返回应用程序连接到的窗口系统,所关联的所有屏幕的列表。
返回当前 会话的 标识符。
若应用程序已从早期会话还原,此标识符与先前会话标识符相同。会话标识符保证,对于不同应用程序和同一应用程序的不同实例是唯一的。
另请参阅 isSessionRestored (), sessionKey (), commitDataRequest (),和 saveStateRequest ().
返回会话键,在当前 session .
若应用程序已从早期会话还原,此键与先前会话结束时的键相同。
会话键将改变,每次保存会话时。若关闭过程被取消,再次关闭时将使用另一会话键。
另请参阅 isSessionRestored (), sessionId (), commitDataRequest (),和 saveStateRequest ().
[slot, since 6.5]
void
QGuiApplication::
setBadgeNumber
(
qint64
number
)
Sets the application's badge to number .
Useful for providing feedback to the user about the number of unread messages or similar.
The badge will be overlaid on the application's icon in the Dock on macOS, the home screen icon on iOS, or the task bar on Windows and Linux.
If the number is outside the range supported by the platform, the number will be clamped to the supported range. If the number does not fit within the badge, the number may be visually elided.
Setting the number to 0 will clear the badge.
该函数在 Qt 6.5 引入。
另请参阅 applicationName .
[static]
void
QGuiApplication::
setDesktopSettingsAware
(
bool
on
)
将 Qt 是否应使用系统标准颜色、字体等设为
on
。默认情况下,这是
true
.
此函数必须先被调用才创建 QGuiApplication 对象,像这样:
int main(int argc, char *argv[]) { QApplication::setDesktopSettingsAware(false); QApplication app(argc, argv); // ... return app.exec(); }
另请参阅 desktopSettingsAware ().
[static]
void
QGuiApplication::
setFont
(const
QFont
&
font
)
将应用程序默认字体改为 font .
另请参阅 font ().
[static]
void
QGuiApplication::
setHighDpiScaleFactorRoundingPolicy
(
Qt::HighDpiScaleFactorRoundingPolicy
policy
)
Sets the high-DPI scale factor rounding policy for the application. The policy decides how non-integer scale factors (such as Windows 150%) are handled.
The two principal options are whether fractional scale factors should be rounded to an integer or not. Keeping the scale factor as-is will make the user interface size match the OS setting exactly, but may cause painting errors, for example with the Windows style.
If rounding is wanted, then which type of rounding should be decided next. Mathematically correct rounding is supported but may not give the best visual results: Consider if you want to render 1.5x as 1x ("small UI") or as 2x ("large UI"). See the Qt::HighDpiScaleFactorRoundingPolicy enum for a complete list of all options.
This function must be called before creating the application object. The QGuiApplication::highDpiScaleFactorRoundingPolicy () accessor will reflect the environment, if set.
默认值为 Qt::HighDpiScaleFactorRoundingPolicy::PassThrough .
另请参阅 highDpiScaleFactorRoundingPolicy ().
[static]
void
QGuiApplication::
setOverrideCursor
(const
QCursor
&
cursor
)
将应用程序覆盖光标设为 cursor .
应用程序覆盖光标旨在向用户展示应用程序处于特殊状态,例如:在可能需要一些时间的操作期间。
此光标将显示在所有应用程序的 Widget 中,直到 restoreOverrideCursor () 或另一 setOverrideCursor() 被调用。
应用程序光标存储在内部堆栈中。setOverrideCursor() 将光标压入堆栈,而 restoreOverrideCursor () 将活动光标从堆栈中弹出。 changeOverrideCursor () 更改当前活动应用程序的覆盖光标。
每个 setOverrideCursor() 之后最终必须跟随相应 restoreOverrideCursor (),否则,将从不清空堆栈。
范例:
QGuiApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); calculateHugeMandelbrot(); // lunch time... QGuiApplication::restoreOverrideCursor();
另请参阅 overrideCursor (), restoreOverrideCursor (), changeOverrideCursor (),和 QWidget::setCursor ().
[static]
void
QGuiApplication::
setPalette
(const
QPalette
&
pal
)
将应用程序调色板更改为 pal .
来自此调色板的颜色角色与系统平台主题组合,形成应用程序的最终调色板。
另请参阅 palette ().
[static]
QStyleHints
*QGuiApplication::
styleHints
()
返回应用程序的样式提示。
样式提示封装了一组从属平台特性,譬如:双击间隔、全宽选定、等。
提示可以用于与底层平台更紧密集成。
另请参阅 QStyleHints .
[static]
void
QGuiApplication::
sync
()
可以用于将 Qt 状态和窗口系统状态同步的函数。
此函数将首先清空 Qt 事件通过调用 QCoreApplication::processEvents (),然后平台插件同步窗口系统,最后交付 Qt 事件通过另一调用 QCoreApplication::processEvents ();
此函数很耗时,且不鼓励使用它。
[static]
QWindow
*QGuiApplication::
topLevelAt
(const
QPoint
&
pos
)
返回顶层窗口在给定位置 pos ,若有的话。
[static]
QWindowList
QGuiApplication::
topLevelWindows
()
返回应用程序顶层窗口列表。
另请参阅 allWindows ().
引用唯一应用程序对象的全局指针。才可有效使用当对象是 QGuiApplication .
另请参阅 QCoreApplication::instance () 和 qApp .