QGuiApplication 類管理 GUI 應用程序的控製流和主要設置。 更多...
| 頭: | #include <QGuiApplication> |
| qmake: | QT += gui |
| Since: | Qt 5.0 |
| 繼承: | QCoreApplication |
| 繼承者: |
該類在 Qt 5.0 引入。
|
|
| QGuiApplication (int & argc , char ** argv ) | |
| virtual | ~QGuiApplication () |
| qreal | devicePixelRatio () const |
| bool | isSavingSession () const |
| bool | isSessionRestored () const |
| QString | sessionId () const |
| QString | sessionKey () const |
| virtual bool | notify (QObject * object , QEvent * event ) override |
| void | applicationDisplayNameChanged () |
| void | applicationStateChanged (Qt::ApplicationState state ) |
| void | commitDataRequest (QSessionManager & manager ) |
| void | focusObjectChanged (QObject * focusObject ) |
| void | focusWindowChanged (QWindow * focusWindow ) |
| void | fontChanged (const QFont & font ) |
| void | fontDatabaseChanged () |
| void | lastWindowClosed () |
| void | layoutDirectionChanged (Qt::LayoutDirection direction ) |
| void | paletteChanged (const QPalette & palette ) |
| 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 | isFallbackSessionManagementEnabled () |
| bool | isLeftToRight () |
| bool | isRightToLeft () |
| Qt::KeyboardModifiers | keyboardModifiers () |
| Qt::LayoutDirection | layoutDirection () |
| QWindow * | modalWindow () |
| Qt::MouseButtons | mouseButtons () |
| QCursor * | overrideCursor () |
| QPalette | palette () |
| QFunctionPointer | platformFunction (const QByteArray & function ) |
| QString | platformName () |
| QPlatformNativeInterface * | platformNativeInterface () |
| 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 | setFallbackSessionManagementEnabled (bool enabled ) |
| 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 (), hasPendingEvents(), notify (). |
| Windows | allWindows (), topLevelWindows (), focusWindow (), clipboard (), topLevelAt (). |
| 高級光標處理 | overrideCursor (), setOverrideCursor (), restoreOverrideCursor (). |
| 會話管理 | isSessionRestored (), sessionId (), commitDataRequest (), saveStateRequest (). |
| 雜項 | startingUp (), closingDown (). |
另請參閱 QCoreApplication , QAbstractEventDispatcher ,和 QEventLoop .
此特性保持此應用程序的用戶可見名稱
此名稱將展示給用戶,例如在窗口標題中。 可以翻譯它,若有必要。
若未設置,應用程序顯示名稱默認為應用程序名稱。
該特性在 Qt 5.0 引入。
訪問函數:
| QString | applicationDisplayName () |
| void | setApplicationDisplayName (const QString & name ) |
通知程序信號:
| void | applicationDisplayNameChanged () |
另請參閱 applicationName .
此特性保持用於此應用程序桌麵條目的基本名稱
這是錶示此應用程序桌麵條目的文件名 (不帶完整路徑),根據 freedesktop 桌麵條目規範。
此特性給齣什麼桌麵條目錶示應用程序的精密指示,且窗口係統需要在不求助於不精密試探的情況下檢索這種信息。
可以獲得最新版本的 freedesktop 桌麵條目規範 here .
該特性在 Qt 5.7 引入。
訪問函數:
| QString | desktopFileName () |
| void | setDesktopFileName (const QString & name ) |
此特性保持用於此應用程序的默認布局方嚮
當係統啓動時,默認布局方嚮從屬應用程序的語言。
通知信號在 Qt 5.4 引入。
訪問函數:
| Qt::LayoutDirection | layoutDirection () |
| void | setLayoutDirection (Qt::LayoutDirection direction ) |
通知程序信號:
| void | layoutDirectionChanged (Qt::LayoutDirection direction ) |
另請參閱 QWidget::layoutDirection , isLeftToRight (),和 isRightToLeft ().
此特性保持底層平颱插件的名稱。
QPA 平颱插件位於
qtbase\src\plugins\platforms
。當撰寫本文時,支持下列平颱插件名稱:
android
cocoa
是 macOS 平颱插件。
directfb
eglfs
是無需實際窗口係統 (像 X11 或 Wayland) 在 EGL 和 OpenGL ES 2.0 之上運行 Qt5 應用程序的平颱插件。更多信息,見
EGLFS
.
ios
(還用於 tvOS)
kms
是實驗性平颱插件使用內核模式設置和
DRM
(直接渲染管理器)。
linuxfb
直接寫入幀緩衝。更多信息,見
LinuxFB
.
minimal
為想要編寫自己平颱插件的開發者提供範例。不管怎樣,可以使用插件在沒有 GUI 的環境下運行 GUI 應用程序,譬如:服務器。
minimalegl
是範例插件。
offscreen
openwfd
qnx
windows
wayland
是用於現代 Linux 桌麵和一些嵌入式係統的平颱插件。
xcb
是用於常規桌麵 Linux 平颱的 X11 插件。
關於嵌入式 Linux 設備平颱插件的更多信息,見 Qt for Embedded Linux .
訪問函數:
| QString | platformName () |
此特性保持應用程序的首要 (或默認) 屏幕。
這將是最初展示 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 必須在 QGuiApplication 對象的整個生命周期內保持有效。此外, 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
,指定要加載的額外插件。自變量可能齣現多次。
串聯插件按
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
,檢測鍵
AltGr
發現在某些鍵盤是作為
Qt::GroupSwitchModifier
(從 Qt 5.12 起)。
darkmode=[1|2]
控製 Qt 如何響應激活的
用於應用程序的暗黑模式
引入在 Windows 10 1903(從 Qt 5.15 起)。
1 值導緻 Qt 將窗口邊框切換為黑色,當 用於應用程序的暗黑模式 被激活且未使用高對比度主題。這旨在為應用程序實現自己的主題化。
此外,2 值導緻 Windows Vista 風格被取消激活,並切換到使用簡化調色闆的暗黑模式 Windows 風格。目前這是實驗性的,直到引入正確適配暗黑模式的新風格為止。
dialogs=[xp|none]
,
xp
使用 XP 風格本機對話框和
none
禁用它們。
dpiawareness=[0|1|2]
Sets the DPI awareness of the process (see
高 DPI 顯示
,從 Qt 5.4 起)。
fontengine=freetype
,使用
FreeType
字體引擎。
menus=[native|none]
,控製本機菜單的使用。
本機菜單的實現是使用 Win32 API 且更簡單相比 QMenu 基菜單,例如,它們允許放置 Widget 或改變像字體特性等,但不提供懸停信號。它們主要旨在用於 Qt Quick。默認情況下,將使用它們,若應用程序不是實例化的 QApplication 或對於 Qt Quick Controls 2 應用程序 (從 Qt 5.10 起)。
nocolorfonts
關閉 DirectWrite Color 字體 (從 Qt 5.8 起)。
nodirectwrite
關閉 DirectWrite 字體 (從 Qt 5.8 起)。
nomousefromtouch
忽略由 OS (操作係統) 從觸摸事件閤成的鼠標事件。
nowmpointer
從指針輸入消息處理切換到傳統鼠標處理 (從 Qt 5.12 起)。
reverse
激活從右到左模式 (實驗性)。Windows 標題欄將以從右到左區域設置方式相應展示 (從 Qt 5.13 起)。
tabletabsoluterange=<value>
Sets a value for mouse mode detection of
WinTab
tablets (Legacy, since Qt 5.3).
下列參數可用於
-platform cocoa
(在 macOS):
fontengine=freetype
,使用
FreeType
字體引擎。
關於可用於嵌入式 Linux 平颱的特定平颱自變量的更多信息,見 Qt for Embedded Linux .
另請參閱 arguments () 和 QGuiApplication::platformName .
[signal]
void
QGuiApplication::
applicationStateChanged
(
Qt::ApplicationState
state
)
此信號發射,當 state 對於應用程序改變。
該函數在 Qt 5.2 引入。
另請參閱 applicationState ().
[signal]
void
QGuiApplication::
commitDataRequest
(
QSessionManager
&
manager
)
此信號處理 會話管理 。它被發射當 QSessionManager 想要應用程序提交其所有數據。
通常這意味著保存所有打開文件,在從用戶獲得權限後。此外,可能想要提供由用戶可以取消關閉的手段。
不應退齣應用程序,在此信號內。相反,會話管理器可以 (或不可以) 之後這樣做,從屬上下文。
警告: 在此信號內,不可能進行用戶交互, unless 要求 manager 明確權限。見 QSessionManager::allowsInteraction () 和 QSessionManager::allowsErrorInteraction () 瞭解細節和範例用法。
注意: 應使用 Qt::DirectConnection 當連接到此信號時。
該函數在 Qt 4.2 引入。
另請參閱 setFallbackSessionManagementEnabled (), isSessionRestored (), sessionId (), saveStateRequest (),和 會話管理 .
[signal]
void
QGuiApplication::
focusObjectChanged
(
QObject
*
focusObject
)
此信號被發射,當聚焦捆綁事件的最終接收者改變時。 focusObject 是新接收者。
另請參閱 focusObject ().
[signal]
void
QGuiApplication::
focusWindowChanged
(
QWindow
*
focusWindow
)
此信號發射,當聚焦窗口改變時。 focusWindow 是新聚焦窗口。
另請參閱 focusWindow ().
[signal]
void
QGuiApplication::
fontChanged
(const
QFont
&
font
)
此信號發射,當 font 對於應用程序改變。
該函數在 Qt 5.11 引入。
另請參閱 font ().
[signal]
void
QGuiApplication::
fontDatabaseChanged
()
此信號發射,當加載 (或移除) 應用程序字體時。
另請參閱 QFontDatabase::addApplicationFont (), QFontDatabase::addApplicationFontFromData (), QFontDatabase::removeAllApplicationFonts (),和 QFontDatabase::removeApplicationFont ().
[signal]
void
QGuiApplication::
lastWindowClosed
()
此信號被發射從 exec () 當關閉最後一個可見首要窗口 (即:窗口沒有父級) 時。
默認情況下,
QGuiApplication
離開在此信號發射後。可以關閉此特徵通過設置
quitOnLastWindowClosed
to
false
.
另請參閱 QWindow::close () 和 QWindow::isTopLevel ().
[signal]
void
QGuiApplication::
paletteChanged
(const
QPalette
&
palette
)
此信號發射,當 palette 對於應用程序改變。
該函數在 Qt 5.4 引入。
另請參閱 palette ().
[signal]
void
QGuiApplication::
saveStateRequest
(
QSessionManager
&
manager
)
此信號處理 會話管理 。它被援引當 會話管理器 想要應用程序為未來會話保留其狀態。
例如,文本編輯器將創建臨時文件 (包括當前編輯緩衝內容、光標位置及當前編輯會話的其它方麵)。
從不應該在此信號中,退齣應用程序。取而代之,會話管理器可以 (或不可以) 在此之後履行,從屬上下文。此外,大多數會話管理器很可能立即請求保存狀態,在應用程序啓動後。這準許會話管理器,瞭解應用程序的重啓策略。
警告: 在此信號內,不可能進行用戶交互, unless 要求 manager 明確權限。見 QSessionManager::allowsInteraction () 和 QSessionManager::allowsErrorInteraction () 瞭解細節。
注意: 應使用 Qt::DirectConnection 當連接到此信號時。
該函數在 Qt 4.2 引入。
另請參閱 isSessionRestored (), sessionId (), commitDataRequest (),和 會話管理 .
[signal]
void
QGuiApplication::
screenAdded
(
QScreen
*
screen
)
此信號發射每當新屏幕 screen 已添加到係統。
另請參閱 screens (), primaryScreen ,和 screenRemoved ().
[signal]
void
QGuiApplication::
screenRemoved
(
QScreen
*
screen
)
此信號發射,每當 screen 被移除從係統。它提供瞭管理屏幕窗口的機會,在 Qt 迴退以將它們移到首要屏幕之前。
該函數在 Qt 5.4 引入。
另請參閱 screens (), screenAdded (), QObject::destroyed (),和 QWindow::setScreen ().
[虛擬]
QGuiApplication::
~QGuiApplication
()
銷毀應用程序。
[static]
QWindowList
QGuiApplication::
allWindows
()
返迴應用程序所有窗口的列錶。
列錶為空,若沒有窗口。
另請參閱 topLevelWindows ().
[static]
Qt::ApplicationState
QGuiApplication::
applicationState
()
返迴應用程序的當前狀態。
可以對應用程序狀態改變做齣反應,以履行譬如:停止/再繼續 CPU 密集型任務、釋放/加載資源、或保存/還原應用程序數據。
該函數在 Qt 5.2 引入。
[static]
void
QGuiApplication::
changeOverrideCursor
(const
QCursor
&
cursor
)
將當前活動應用程序的覆蓋光標改為 cursor .
此函數不起作用若 setOverrideCursor () 未被調用。
另請參閱 setOverrideCursor (), overrideCursor (), restoreOverrideCursor (),和 QWidget::setCursor ().
[static]
QClipboard
*QGuiApplication::
clipboard
()
返迴與剪貼闆交互的對象。
[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 在當前活動窗口,將是聚焦捆綁事件 (譬如:鍵事件) 的最終接收者。
[static]
QWindow
*QGuiApplication::
focusWindow
()
返迴 QWindow 接收聚焦捆綁事件,譬如:鍵事件。
[static]
QFont
QGuiApplication::
font
()
返迴應用程序的默認字體。
另請參閱 setFont ().
[static]
Qt::HighDpiScaleFactorRoundingPolicy
QGuiApplication::
highDpiScaleFactorRoundingPolicy
()
返迴高 DPI (每英寸點數) 比例縮放因子捨入策略。
該函數在 Qt 5.14 引入。
另請參閱 setHighDpiScaleFactorRoundingPolicy ().
[static]
QInputMethod
*QGuiApplication::
inputMethod
()
返迴輸入法。
輸入法返迴虛擬鍵盤狀態和位置的有關特性。它還提供當前聚焦輸入元素位置的有關信息。
另請參閱 QInputMethod .
[static]
bool
QGuiApplication::
isFallbackSessionManagementEnabled
()
返迴是否 QGuiApplication 將使用迴退會話管理。
默認為
true
.
若這為
true
且會話管理器允許用戶交互,
QGuiApplication
將試著關閉頂層窗口後於
commitDataRequest
() 已發射。若窗口無法關閉,將取消會話關閉且應用程序將保持運行。
迴退會話管理隻對擁有 "確定想要關閉此窗口?" 特徵 (或根據某些條件阻止關閉頂層窗口,且要明確實現會話管理什麼都不做的其它邏輯) 的應用程序有利。若應用程序 do 實現會話管理是使用適當會話管理 API,迴退會話管理會乾擾且可能破壞會話管理邏輯。
警告:
若所有窗口
are
被關閉由於迴退會話管理且
quitOnLastWindowClosed
() 是
true
,應用程序將離開,在透過平颱會話管理協議明確指導其離開前。違反協議可能阻止平颱會話管理器保存應用程序狀態。
該函數在 Qt 5.6 引入。
另請參閱 setFallbackSessionManagementEnabled (), QSessionManager::allowsInteraction (), saveStateRequest (), commitDataRequest (),和 會話管理 .
[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
() 發射,且之後通過會話管理關閉窗口時也如此。
該函數在 Qt 5.0 引入。
另請參閱 sessionId (), commitDataRequest (),和 saveStateRequest ().
返迴
true
若應用程序已還原從較早
session
;否則返迴
false
.
另請參閱 sessionId (), commitDataRequest (),和 saveStateRequest ().
[static]
Qt::KeyboardModifiers
QGuiApplication::
keyboardModifiers
()
返迴鍵盤修飾符鍵的當前狀態。當前狀態會被同步更新,當事件隊列中的自發改變鍵盤狀態的事件被清空時 ( QEvent::KeyPress and QEvent::KeyRelease 事件)。
應注意,這可能不反映調用時在輸入設備上保持的實際鍵,但反映上述事件之一最後報告的修飾符。若沒有保持鍵, Qt::NoModifier 被返迴。
另請參閱 mouseButtons () 和 queryKeyboardModifiers ().
[static]
QWindow
*QGuiApplication::
modalWindow
()
返迴最近展示的模態窗口。若沒有可見的模態窗口,此函數返迴 0。
模態窗口這種窗口有它自己的 modality 特性被設為 Qt::WindowModal or Qt::ApplicationModal 。必須關閉模態窗口,在用戶可以繼續使用程序其它部分前。
模態窗口被組織在堆棧中。此函數返迴在堆棧頂部的模態窗口。
另請參閱 Qt::WindowModality and QWindow::setModality ().
[static]
Qt::MouseButtons
QGuiApplication::
mouseButtons
()
返迴鼠標按鈕的當前狀態。同步更新當前狀態,在事件隊列事件清空將自發改變鼠標狀態時 ( QEvent::MouseButtonPress and QEvent::MouseButtonRelease 事件)。
應該注意的是,這可能不反映調用時輸入設備保持的實際按鈕,而是某一上述事件最後報告的鼠標按鈕。若未按住鼠標按鈕 Qt::NoButton 被返迴。
另請參閱 keyboardModifiers ().
[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]
QFunctionPointer
QGuiApplication::
platformFunction
(const
QByteArray
&
function
)
返迴的函數指針來自 platformplugin 匹配 function
[static]
QPlatformNativeInterface
*QGuiApplication::
platformNativeInterface
()
返迴平颱本機接口,用於特定平颱功能。
[static]
Qt::KeyboardModifiers
QGuiApplication::
queryKeyboardModifiers
()
查詢並返迴鍵盤修飾符鍵的狀態。不像 keyboardModifiers 此方法返迴調用方法時保持在輸入設備上的實際鍵。
它不依賴必須由此進程接收的鍵按下事件,譬如:這使得當移動窗口時校驗修飾符成為可能。注意:在大多數情況下,應使用 keyboardModifiers (),其更快更準確,因為它包含的修飾符狀態 (如同接收當前處理事件時狀態)。
另請參閱 keyboardModifiers ().
[static]
void
QGuiApplication::
restoreOverrideCursor
()
撤消最後 setOverrideCursor ().
若 setOverrideCursor () 被調用 2 次,調用 restoreOverrideCursor() 將激活第 1 次光標設置。第 2 次調用此函數將還原 Widget 的原始光標。
另請參閱 setOverrideCursor () 和 overrideCursor ().
[static]
QScreen
*QGuiApplication::
screenAt
(const
QPoint
&
point
)
返迴的屏幕位於
point
,或
nullptr
若在任何屏幕外。
The
point
與各虛擬同級集的 virtualGeometry() 相關。若點映射到多個虛擬同級集,則返迴首個匹配。若隻希望搜索已知屏幕的虛擬桌麵同級 (例如:屏幕同級對於應用程序窗口
QWidget::windowHandle()->screen()
),使用
QScreen::virtualSiblingAt
().
該函數在 Qt 5.10 引入。
[static]
QList
<
QScreen
*> QGuiApplication::
screens
()
返迴應用程序連接到的窗口係統,所關聯的所有屏幕的列錶。
返迴當前 會話的 標識符。
若應用程序已從早期會話還原,此標識符與先前會話標識符相同。會話標識符保證,對於不同應用程序和同一應用程序的不同實例是唯一的。
另請參閱 isSessionRestored (), sessionKey (), commitDataRequest (),和 saveStateRequest ().
返迴會話鍵,在當前 session .
若應用程序已從早期會話還原,此鍵與先前會話結束時的鍵相同。
會話鍵將改變,每次保存會話時。若關閉過程被取消,再次關閉時將使用另一會話鍵。
另請參閱 isSessionRestored (), sessionId (), commitDataRequest (),和 saveStateRequest ().
[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::
setFallbackSessionManagementEnabled
(
bool
enabled
)
設置是否 QGuiApplication 使用迴退會話管理為 enabled .
該函數在 Qt 5.6 引入。
另請參閱 isFallbackSessionManagementEnabled ().
[static]
void
QGuiApplication::
setFont
(const
QFont
&
font
)
將應用程序默認字體改為 font .
另請參閱 font ().
[static]
void
QGuiApplication::
setHighDpiScaleFactorRoundingPolicy
(
Qt::HighDpiScaleFactorRoundingPolicy
policy
)
設置用於應用程序的高 DPI (每英寸點數) 比例縮放因子捨入策略。 policy decides how non-integer scale factors (such as Windows 150%) are handled, for applications that have AA_EnableHighDpiScaling enabled.
2 親代選項是,是否應四捨五入成整數的小數比例縮放因子。保持比例縮放因子不變將使 UI (用戶界麵) 大小準確匹配 OS (操作係統) 設置,但可能導緻描繪錯誤 (例如:采用 Windows 風格)。
若想要四捨五入,那麼接下來應決定哪種四捨五入類型。數學正確的四捨五入是支持的,但不可能給齣最佳視覺結果:考慮一下,若想要把 1.5x 渲染成 1x (小 UI) 或 2x (大 UI)。見 Qt::HighDpiScaleFactorRoundingPolicy 枚舉,瞭解所有選項的完整列錶。
This function must be called before creating the application object, and can be overridden by setting the QT_SCALE_FACTOR_ROUNDING_POLICY environment variable. The QGuiApplication::highDpiScaleFactorRoundingPolicy () 訪問器將反射環境,若有設置。
The default value is Qt::HighDpiScaleFactorRoundingPolicy::Round. On Qt for Android the default is Qt::HighDpiScaleFactorRoundingPolicy::PassThrough, which preserves historical behavior from earlier Qt versions.
該函數在 Qt 5.14 引入。
另請參閱 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 ();
此函數很耗時,且不鼓勵使用它。
該函數在 Qt 5.2 引入。
[static]
QWindow
*QGuiApplication::
topLevelAt
(const
QPoint
&
pos
)
返迴頂層窗口在給定位置 pos ,若有的話。
[static]
QWindowList
QGuiApplication::
topLevelWindows
()
返迴應用程序頂層窗口列錶。
另請參閱 allWindows ().
引用唯一應用程序對象的全局指針。纔可有效使用當對象是 QGuiApplication .
另請參閱 QCoreApplication::instance () 和 qApp .