内容表

上一话题

QGradient

下一话题

QHelpEvent

QGuiApplication

QGuiApplication class manages the GUI application’s control flow and main settings. 更多

Inheritance diagram of PySide2.QtGui.QGuiApplication

继承者: QApplication

概要

详细描述

QGuiApplication contains 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, QGuiApplication handles most of the system-wide and application-wide settings.

For any GUI application using Qt, there is precisely one QGuiApplication object no matter whether the application has 0, 1, 2 or more windows at any given time. For non-GUI Qt applications, use QCoreApplication instead, as it does not depend on the Qt GUI module. For QWidget based Qt applications, use QApplication instead, as it provides some functionality needed for creating QWidget 实例。

QGuiApplication object is accessible through the instance() function, which returns a pointer equivalent to the global qApp 指针。

QGuiApplication ‘s main areas of responsibility are:

  • It initializes the application with the user’s desktop settings, such as palette() , font() and styleHints() . 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() and postEvent() .

  • 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 of topLevelWindows() ,等。

  • 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() and commitDataRequest() and saveStateRequest() 了解细节。

由于 QGuiApplication object does so much initialization, it must be created before any other objects related to the user interface are created. QGuiApplication also deals with common command line arguments. Hence, it is usually a good idea to create it before any interpretation or modification of argv is 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() .

class QGuiApplication

QGuiApplication(arg__1)

参数

arg__1 – 字符串列表

static PySide2.QtGui.QGuiApplication. allWindows ( )
返回类型

Returns a list of all the windows in the application.

The list is empty if there are no windows.

另请参阅

topLevelWindows()

static PySide2.QtGui.QGuiApplication. applicationDisplayName ( )
返回类型

unicode

PySide2.QtGui.QGuiApplication. applicationDisplayNameChanged ( )
static 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

static PySide2.QtGui.QGuiApplication. changeOverrideCursor ( arg__1 )
参数

arg__1 QCursor

Changes the currently active application override cursor to cursor .

此函数不起作用若 setOverrideCursor() was not called.

static PySide2.QtGui.QGuiApplication. clipboard ( )
返回类型

QClipboard

返回与剪贴板进行交互的对象。

PySide2.QtGui.QGuiApplication. commitDataRequest ( sessionManager )
参数

sessionManager QSessionManager

static PySide2.QtGui.QGuiApplication. desktopFileName ( )
返回类型

unicode

static 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() 代替。

static 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

static PySide2.QtGui.QGuiApplication. focusWindow ( )
返回类型

QWindow

返回 QWindow that receives events tied to focus, such as key events.

PySide2.QtGui.QGuiApplication. focusWindowChanged ( focusWindow )
参数

focusWindow QWindow

static PySide2.QtGui.QGuiApplication. font ( )
返回类型

QFont

返回默认的应用程序字体。

另请参阅

setFont()

PySide2.QtGui.QGuiApplication. fontChanged ( font )
参数

font QFont

PySide2.QtGui.QGuiApplication. fontDatabaseChanged ( )
static PySide2.QtGui.QGuiApplication. highDpiScaleFactorRoundingPolicy ( )
返回类型

HighDpiScaleFactorRoundingPolicy

Returns the high-DPI scale factor rounding policy.

static 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

static 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.

static PySide2.QtGui.QGuiApplication. isLeftToRight ( )
返回类型

bool

返回 true if the application’s layout direction is LeftToRight ;否则返回 false .

static 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 .

static PySide2.QtGui.QGuiApplication. keyboardModifiers ( )
返回类型

KeyboardModifiers

返回键盘修饰符键的当前状态。当前状态会被同步更新,当事件队列中的自发改变键盘状态的事件被清空时 ( KeyPress and KeyRelease 事件)。

应注意,这可能不反映调用时在输入设备上保持的实际键,而反映上述事件之一最后报告的修饰符。若没有被保持的键, NoModifier 被返回。

PySide2.QtGui.QGuiApplication. lastWindowClosed ( )
static PySide2.QtGui.QGuiApplication. layoutDirection ( )
返回类型

LayoutDirection

PySide2.QtGui.QGuiApplication. layoutDirectionChanged ( direction )
参数

direction LayoutDirection

static PySide2.QtGui.QGuiApplication. modalWindow ( )
返回类型

QWindow

返回最近展示的模态窗口。若没有可见的模态窗口,此函数返回 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()

static 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 被返回。

static PySide2.QtGui.QGuiApplication. overrideCursor ( )
返回类型

QCursor

返回活动应用程序的覆盖光标。

此函数返回 None 若应用程序光标没有定义 (即:内部光标堆栈为空)。

static PySide2.QtGui.QGuiApplication. palette ( )
返回类型

QPalette

返回当前应用程序调色板。

Roles that have not been explicitly set will reflect the system’s platform theme.

另请参阅

setPalette()

PySide2.QtGui.QGuiApplication. paletteChanged ( pal )
参数

pal QPalette

static PySide2.QtGui.QGuiApplication. platformName ( )
返回类型

unicode

static PySide2.QtGui.QGuiApplication. primaryScreen ( )
返回类型

QScreen

PySide2.QtGui.QGuiApplication. primaryScreenChanged ( screen )
参数

screen QScreen

static 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.

static PySide2.QtGui.QGuiApplication. quitOnLastWindowClosed ( )
返回类型

bool

static 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

static 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

static 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.

static PySide2.QtGui.QGuiApplication. setApplicationDisplayName ( name )
参数

name – unicode

static PySide2.QtGui.QGuiApplication. setDesktopFileName ( name )
参数

name – unicode

另请参阅

desktopFileName()

static 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();
}
											
static PySide2.QtGui.QGuiApplication. setFallbackSessionManagementEnabled ( arg__1 )
参数

arg__1 bool

Sets whether QGuiApplication will use fallback session management to enabled .

static PySide2.QtGui.QGuiApplication. setFont ( arg__1 )
参数

arg__1 QFont

把默认应用程序字体改为 font .

另请参阅

font()

static 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.

static PySide2.QtGui.QGuiApplication. setLayoutDirection ( direction )
参数

direction LayoutDirection

另请参阅

layoutDirection()

static 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();
											
static 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.

另请参阅

palette()

static PySide2.QtGui.QGuiApplication. setQuitOnLastWindowClosed ( quit )
参数

quit bool

static PySide2.QtGui.QGuiApplication. setWindowIcon ( icon )
参数

icon QIcon

另请参阅

windowIcon()

static 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

static 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.

static PySide2.QtGui.QGuiApplication. topLevelAt ( pos )
参数

pos QPoint

返回类型

QWindow

返回顶层窗口在给定位置 pos ,若有的话。

static PySide2.QtGui.QGuiApplication. topLevelWindows ( )
返回类型

返回应用程序顶层窗口列表。

另请参阅

allWindows()

static PySide2.QtGui.QGuiApplication. windowIcon ( )
返回类型

QIcon

另请参阅

setWindowIcon()