QGuiApplicationclass manages the GUI application’s control flow and main settings. 更多 …
继承者: QApplication
def
devicePixelRatio
()
def
isSavingSession
()
def
isSessionRestored
()
def
sessionId
()
def
sessionKey
()
def
applicationStateChanged
(state)
def
commitDataRequest
(sessionManager)
def
focusObjectChanged
(focusObject)
def
focusWindowChanged
(focusWindow)
def
fontChanged
(font)
def
fontDatabaseChanged
()
def
lastWindowClosed
()
def
layoutDirectionChanged
(direction)
def
paletteChanged
(pal)
def
primaryScreenChanged
(screen)
def
saveStateRequest
(sessionManager)
def
screenAdded
(screen)
def
screenRemoved
(screen)
def
allWindows
()
def
applicationDisplayName
()
def
applicationState
()
def
changeOverrideCursor
(arg__1)
def
clipboard
()
def
desktopFileName
()
def
desktopSettingsAware
()
def
focusObject
()
def
focusWindow
()
def
font
()
def
inputMethod
()
def
isLeftToRight
()
def
isRightToLeft
()
def
keyboardModifiers
()
def
layoutDirection
()
def
modalWindow
()
def
mouseButtons
()
def
overrideCursor
()
def
palette
()
def
platformName
()
def
primaryScreen
()
def
queryKeyboardModifiers
()
def
quitOnLastWindowClosed
()
def
restoreOverrideCursor
()
def
screenAt
(point)
def
screens
()
def
setApplicationDisplayName
(name)
def
setDesktopFileName
(name)
def
setDesktopSettingsAware
(on)
def
setFallbackSessionManagementEnabled
(arg__1)
def
setFont
(arg__1)
def
setHighDpiScaleFactorRoundingPolicy
(policy)
def
setLayoutDirection
(direction)
def
setOverrideCursor
(arg__1)
def
setPalette
(pal)
def
setQuitOnLastWindowClosed
(quit)
def
setWindowIcon
(icon)
def
styleHints
()
def
sync
()
def
topLevelAt
(pos)
def
topLevelWindows
()
def
windowIcon
()
QGuiApplicationcontains the main event loop, where all events from the window system and other sources are processed and dispatched. It also handles the application’s initialization and finalization, and provides session management. In addition,QGuiApplicationhandles most of the system-wide and application-wide settings.For any GUI application using Qt, there is precisely one
QGuiApplicationobject no matter whether the application has 0, 1, 2 or more windows at any given time. For non-GUI Qt applications, useQCoreApplicationinstead, as it does not depend on the Qt GUI module. ForQWidgetbased Qt applications, useQApplicationinstead, as it provides some functionality needed for creatingQWidget实例。
QGuiApplicationobject is accessible through theinstance()function, which returns a pointer equivalent to the globalqApp指针。
QGuiApplication‘s main areas of responsibility are:
It initializes the application with the user’s desktop settings, such as
palette(),font()andstyleHints(). It keeps track of these properties in case the user changes the desktop globally, for example, through some kind of control panel.It performs event handling, meaning that it receives events from the underlying window system and dispatches them to the relevant widgets. You can send your own events to windows by using
sendEvent()andpostEvent().It parses common command line arguments and sets its internal state accordingly. See the
构造函数 文档编制below for more details.It provides localization of strings that are visible to the user via
translate().It provides some magical objects like the
clipboard().It knows about the application’s windows. You can ask which window is at a certain position using
topLevelAt(), get a list oftopLevelWindows(),等。It manages the application’s mouse cursor handling, see
setOverrideCursor()It provides support for sophisticated session management. This makes it possible for applications to terminate gracefully when the user logs out, to cancel a shutdown process if termination isn’t possible and even to preserve the entire application’s state for a future session. See
isSessionRestored(),sessionId()andcommitDataRequest()andsaveStateRequest()了解细节。由于
QGuiApplicationobject does so much initialization, it must be created before any other objects related to the user interface are created.QGuiApplicationalso deals with common command line arguments. Hence, it is usually a good idea to create it before any interpretation or modification ofargvis done in the application itself.
函数组
系统设置
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().
QGuiApplication
¶
QGuiApplication(arg__1)
arg__1 – 字符串列表
PySide2.QtGui.QGuiApplication.
allWindows
(
)
¶
Returns a list of all the windows in the application.
The list is empty if there are no windows.
另请参阅
PySide2.QtGui.QGuiApplication.
applicationDisplayName
(
)
¶
unicode
PySide2.QtGui.QGuiApplication.
applicationDisplayNameChanged
(
)
¶
PySide2.QtGui.QGuiApplication.
applicationState
(
)
¶
ApplicationState
返回应用程序的当前状态。
You can react to application state changes to perform actions such as stopping/resuming CPU-intensive tasks, freeing/loading resources or saving/restoring application data.
PySide2.QtGui.QGuiApplication.
applicationStateChanged
(
state
)
¶
state
–
ApplicationState
PySide2.QtGui.QGuiApplication.
changeOverrideCursor
(
arg__1
)
¶
arg__1
–
QCursor
Changes the currently active application override cursor to
cursor
.
此函数不起作用若
setOverrideCursor()
was not called.
另请参阅
setOverrideCursor()
overrideCursor()
restoreOverrideCursor()
setCursor()
PySide2.QtGui.QGuiApplication.
clipboard
(
)
¶
QClipboard
返回与剪贴板进行交互的对象。
PySide2.QtGui.QGuiApplication.
commitDataRequest
(
sessionManager
)
¶
sessionManager
–
QSessionManager
PySide2.QtGui.QGuiApplication.
desktopFileName
(
)
¶
unicode
另请参阅
PySide2.QtGui.QGuiApplication.
desktopSettingsAware
(
)
¶
bool
返回
true
if Qt is set to use the system’s standard colors, fonts, etc.; otherwise returns
false
。默认为
true
.
PySide2.QtGui.QGuiApplication.
devicePixelRatio
(
)
¶
qreal
Returns the highest screen device pixel ratio found on the system. This is the ratio between physical pixels and device-independent pixels.
Use this function only when you don’t know which window you are targeting. If you do know the target window, use
devicePixelRatio()
代替。
另请参阅
PySide2.QtGui.QGuiApplication.
focusObject
(
)
¶
QObject
返回
QObject
in currently active window that will be final receiver of events tied to focus, such as key events.
PySide2.QtGui.QGuiApplication.
focusObjectChanged
(
focusObject
)
¶
focusObject
–
QObject
PySide2.QtGui.QGuiApplication.
focusWindow
(
)
¶
返回
QWindow
that receives events tied to focus, such as key events.
PySide2.QtGui.QGuiApplication.
fontDatabaseChanged
(
)
¶
PySide2.QtGui.QGuiApplication.
highDpiScaleFactorRoundingPolicy
(
)
¶
HighDpiScaleFactorRoundingPolicy
Returns the high-DPI scale factor rounding policy.
PySide2.QtGui.QGuiApplication.
inputMethod
(
)
¶
QInputMethod
returns the input method.
The input method returns properties about the state and position of the virtual keyboard. It also provides information about the position of the current focused input element.
另请参阅
QInputMethod
PySide2.QtGui.QGuiApplication.
isFallbackSessionManagementEnabled
(
)
¶
bool
Returns whether
QGuiApplication
will use fallback session management.
默认为
true
.
If this is
true
and the session manager allows user interaction,
QGuiApplication
will try to close toplevel windows after
commitDataRequest()
has been emitted. If a window cannot be closed, session shutdown will be canceled and the application will keep running.
Fallback session management only benefits applications that have an “are you sure you want to close this window?” feature or other logic that prevents closing a toplevel window depending on certain conditions, and that do nothing to explicitly implement session management. In applications that do implement session management using the proper session management API, fallback session management interferes and may break session management logic.
警告
If all windows
are
closed due to fallback session management and
quitOnLastWindowClosed()
is
true
, the application will quit before it is explicitly instructed to quit through the platform’s session management protocol. That violation of protocol may prevent the platform session manager from saving application state.
另请参阅
setFallbackSessionManagementEnabled()
allowsInteraction()
saveStateRequest()
commitDataRequest()
Session
Management
PySide2.QtGui.QGuiApplication.
isLeftToRight
(
)
¶
bool
返回
true
if the application’s layout direction is
LeftToRight
;否则返回
false
.
PySide2.QtGui.QGuiApplication.
isRightToLeft
(
)
¶
bool
返回
true
if the application’s layout direction is
RightToLeft
;否则返回
false
.
PySide2.QtGui.QGuiApplication.
isSavingSession
(
)
¶
bool
返回
true
if the application is currently saving the session; otherwise returns
false
.
This is
true
when
commitDataRequest()
and
saveStateRequest()
are emitted, but also when the windows are closed afterwards by session management.
PySide2.QtGui.QGuiApplication.
isSessionRestored
(
)
¶
bool
返回
true
if the application has been restored from an earlier session; otherwise returns
false
.
PySide2.QtGui.QGuiApplication.
keyboardModifiers
(
)
¶
KeyboardModifiers
返回键盘修饰符键的当前状态。当前状态会被同步更新,当事件队列中的自发改变键盘状态的事件被清空时 (
KeyPress
and
KeyRelease
事件)。
应注意,这可能不反映调用时在输入设备上保持的实际键,而反映上述事件之一最后报告的修饰符。若没有被保持的键,
NoModifier
被返回。
PySide2.QtGui.QGuiApplication.
lastWindowClosed
(
)
¶
PySide2.QtGui.QGuiApplication.
layoutDirection
(
)
¶
LayoutDirection
另请参阅
PySide2.QtGui.QGuiApplication.
layoutDirectionChanged
(
direction
)
¶
direction
–
LayoutDirection
PySide2.QtGui.QGuiApplication.
modalWindow
(
)
¶
返回最近展示的模态窗口。若没有可见的模态窗口,此函数返回 0。
A modal window is a window which has its
modality
property set to
WindowModal
or
ApplicationModal
. A modal window must be closed before the user can continue with other parts of the program.
Modal window are organized in a stack. This function returns the modal window at the top of the stack.
另请参阅
WindowModality
setModality()
PySide2.QtGui.QGuiApplication.
mouseButtons
(
)
¶
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 (
MouseButtonPress
and
MouseButtonRelease
事件)。
It should be noted this may not reflect the actual buttons held on the input device at the time of calling but rather the mouse buttons as last reported in one of the above events. If no mouse buttons are being held
NoButton
被返回。
另请参阅
PySide2.QtGui.QGuiApplication.
overrideCursor
(
)
¶
返回活动应用程序的覆盖光标。
此函数返回
None
若应用程序光标没有定义 (即:内部光标堆栈为空)。
PySide2.QtGui.QGuiApplication.
palette
(
)
¶
返回当前应用程序调色板。
Roles that have not been explicitly set will reflect the system’s platform theme.
另请参阅
PySide2.QtGui.QGuiApplication.
platformName
(
)
¶
unicode
PySide2.QtGui.QGuiApplication.
primaryScreen
(
)
¶
QScreen
PySide2.QtGui.QGuiApplication.
primaryScreenChanged
(
screen
)
¶
screen
–
QScreen
PySide2.QtGui.QGuiApplication.
queryKeyboardModifiers
(
)
¶
KeyboardModifiers
查询并返回键盘修饰符键的状态。不像
keyboardModifiers
此方法返回调用方法时保持在输入设备上的实际键。
它不依赖由此进程已接收的键按下事件,譬如:这使得当移动窗口时校验修饰符成为可能。注意:在大多数情况下,应使用
keyboardModifiers()
, which is faster and more accurate since it contains the state of the modifiers as they were when the currently processed event was received.
另请参阅
PySide2.QtGui.QGuiApplication.
quitOnLastWindowClosed
(
)
¶
bool
PySide2.QtGui.QGuiApplication.
restoreOverrideCursor
(
)
¶
撤消最后
setOverrideCursor()
.
若
setOverrideCursor()
has been called twice, calling will activate the first cursor set. Calling this function a second time restores the original widgets’ cursors.
PySide2.QtGui.QGuiApplication.
saveStateRequest
(
sessionManager
)
¶
sessionManager
–
QSessionManager
PySide2.QtGui.QGuiApplication.
screenAdded
(
screen
)
¶
screen
–
QScreen
PySide2.QtGui.QGuiApplication.
screenAt
(
point
)
¶
point
–
QPoint
QScreen
返回屏幕,位于
point
,或
None
若在任何屏幕之外。
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
virtualSiblingAt()
.
PySide2.QtGui.QGuiApplication.
screenRemoved
(
screen
)
¶
screen
–
QScreen
PySide2.QtGui.QGuiApplication.
screens
(
)
¶
返回应用程序连接到的窗口系统,所关联的所有屏幕的列表。
PySide2.QtGui.QGuiApplication.
sessionId
(
)
¶
unicode
Returns the current session’s identifier.
If the application has been restored from an earlier session, this identifier is the same as it was in that previous session. The session identifier is guaranteed to be unique both for different applications and for different instances of the same application.
PySide2.QtGui.QGuiApplication.
sessionKey
(
)
¶
unicode
Returns the session key in the current session.
If the application has been restored from an earlier session, this key is the same as it was when the previous session ended.
The session key changes every time the session is saved. If the shutdown process is cancelled, another session key will be used when shutting down again.
PySide2.QtGui.QGuiApplication.
setApplicationDisplayName
(
name
)
¶
name – unicode
PySide2.QtGui.QGuiApplication.
setDesktopFileName
(
name
)
¶
name – unicode
另请参阅
PySide2.QtGui.QGuiApplication.
setDesktopSettingsAware
(
on
)
¶
on
–
bool
Sets whether Qt should use the system’s standard colors, fonts, etc., to
on
。默认情况下,这是
true
.
此函数必须先被调用才创建
QGuiApplication
对象,像这样:
int main(int argc, char *argv[])
{
QApplication::setDesktopSettingsAware(false);
QApplication app(argc, argv);
...
return app.exec();
}
PySide2.QtGui.QGuiApplication.
setFallbackSessionManagementEnabled
(
arg__1
)
¶
arg__1
–
bool
Sets whether
QGuiApplication
will use fallback session management to
enabled
.
PySide2.QtGui.QGuiApplication.
setFont
(
arg__1
)
¶
arg__1
–
QFont
把默认应用程序字体改为
font
.
另请参阅
PySide2.QtGui.QGuiApplication.
setHighDpiScaleFactorRoundingPolicy
(
policy
)
¶
policy
–
HighDpiScaleFactorRoundingPolicy
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, for applications that have AA_EnableHighDpiScaling enabled.
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
HighDpiScaleFactorRoundingPolicy
enum for a complete list of all options.
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
highDpiScaleFactorRoundingPolicy()
accessor will reflect the environment, if set.
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.
PySide2.QtGui.QGuiApplication.
setLayoutDirection
(
direction
)
¶
direction
–
LayoutDirection
另请参阅
PySide2.QtGui.QGuiApplication.
setOverrideCursor
(
arg__1
)
¶
arg__1
–
QCursor
将应用程序覆盖光标设为
cursor
.
Application override cursors are intended for showing the user that the application is in a special state, for example during an operation that might take some time.
This cursor will be displayed in all the application’s widgets until
restoreOverrideCursor()
or another is called.
Application cursors are stored on an internal stack. pushes the cursor onto the stack, and
restoreOverrideCursor()
pops the active cursor off the stack.
changeOverrideCursor()
changes the curently active application override cursor.
Every must eventually be followed by a corresponding
restoreOverrideCursor()
, otherwise the stack will never be emptied.
范例:
QGuiApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
calculateHugeMandelbrot(); // lunch time...
QGuiApplication::restoreOverrideCursor();
另请参阅
overrideCursor()
restoreOverrideCursor()
changeOverrideCursor()
setCursor()
PySide2.QtGui.QGuiApplication.
setPalette
(
pal
)
¶
pal
–
QPalette
将应用程序调色板更改为
pal
.
The color roles from this palette are combined with the system’s platform theme to form the application’s final palette.
另请参阅
PySide2.QtGui.QGuiApplication.
setQuitOnLastWindowClosed
(
quit
)
¶
quit
–
bool
PySide2.QtGui.QGuiApplication.
styleHints
(
)
¶
QStyleHints
Returns the application’s style hints.
The style hints encapsulate a set of platform dependent properties such as double click intervals, full width selection and others.
The hints can be used to integrate tighter with the underlying platform.
另请参阅
QStyleHints
PySide2.QtGui.QGuiApplication.
sync
(
)
¶
Function that can be used to sync Qt state with the Window Systems state.
This function will first empty Qts events by calling
processEvents()
, then the platform plugin will sync up with the windowsystem, and finally Qts events will be delived by another call to
processEvents()
;
This function is timeconsuming and its use is discouraged.
PySide2.QtGui.QGuiApplication.
topLevelAt
(
pos
)
¶
pos
–
QPoint
返回顶层窗口在给定位置
pos
,若有的话。
PySide2.QtGui.QGuiApplication.
topLevelWindows
(
)
¶
返回应用程序顶层窗口列表。
另请参阅
PySide2.QtGui.QGuiApplication.
windowIcon
(
)
¶
另请参阅