QGuiApplication

The QGuiApplication class manages the GUI application’s control flow and main settings. More

Inheritance diagram of PySide6.QtGui.QGuiApplication

Inherited by: QApplication

Synopsis

Functions

Signals

Static functions

Detailed Description

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

The QGuiApplication object is accessible through the instance() function, which returns a pointer equivalent to the global qApp pointer.

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 constructor documentation 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() , etc.

  • 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() for details.

Since the 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.

Groups of functions

System settings

desktopSettingsAware() , setDesktopSettingsAware() , styleHints() , palette() , setPalette() , font() , setFont() .

Event handling

exec() , processEvents() , exit() , quit() . sendEvent() , postEvent() , sendPostedEvents() , removePostedEvents() , notify() .

Windows

allWindows() , topLevelWindows() , focusWindow() , clipboard() , topLevelAt() .

Advanced cursor handling

overrideCursor() , setOverrideCursor() , restoreOverrideCursor() .

Session management

isSessionRestored() , sessionId() , commitDataRequest() , saveStateRequest() .

Miscellaneous

startingUp() , closingDown() .

See also

QCoreApplication QAbstractEventDispatcher QEventLoop

class PySide6.QtGui.QGuiApplication

PySide6.QtGui.QGuiApplication(arg__1)

Parameters

arg__1 – list of strings

static PySide6.QtGui.QGuiApplication.allWindows()
Return type

Returns a list of all the windows in the application.

The list is empty if there are no windows.

static PySide6.QtGui.QGuiApplication.applicationDisplayName()
Return type

str

This property holds the user-visible name of this application.

This name is shown to the user, for instance in window titles. It can be translated, if necessary.

If not set, the application display name defaults to the application name.

See also

applicationName

PySide6.QtGui.QGuiApplication.applicationDisplayNameChanged()
static PySide6.QtGui.QGuiApplication.applicationState()
Return type

ApplicationState

Returns the current state of the application.

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.

PySide6.QtGui.QGuiApplication.applicationStateChanged(state)
Parameters

stateApplicationState

static PySide6.QtGui.QGuiApplication.changeOverrideCursor(arg__1)
Parameters

arg__1PySide6.QtGui.QCursor

Changes the currently active application override cursor to cursor.

This function has no effect if setOverrideCursor() was not called.

static PySide6.QtGui.QGuiApplication.clipboard()
Return type

PySide6.QtGui.QClipboard

Returns the object for interacting with the clipboard.

PySide6.QtGui.QGuiApplication.commitDataRequest(sessionManager)
Parameters

sessionManagerPySide6.QtGui.QSessionManager

static PySide6.QtGui.QGuiApplication.desktopFileName()
Return type

str

This property holds the base name of the desktop entry for this application.

This is the file name, without the full path, of the desktop entry that represents this application according to the freedesktop desktop entry specification.

This property gives a precise indication of what desktop entry represents the application and it is needed by the windowing system to retrieve such information without resorting to imprecise heuristics.

The latest version of the freedesktop desktop entry specification can be obtained here .

static PySide6.QtGui.QGuiApplication.desktopSettingsAware()
Return type

bool

Returns true if Qt is set to use the system’s standard colors, fonts, etc.; otherwise returns false. The default is true.

PySide6.QtGui.QGuiApplication.devicePixelRatio()
Return type

float

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() instead.

PySide6.QtGui.QGuiApplication.exec_()
Return type

int

static PySide6.QtGui.QGuiApplication.focusObject()
Return type

PySide6.QtCore.QObject

Returns the QObject in currently active window that will be final receiver of events tied to focus, such as key events.

PySide6.QtGui.QGuiApplication.focusObjectChanged(focusObject)
Parameters

focusObjectPySide6.QtCore.QObject

static PySide6.QtGui.QGuiApplication.focusWindow()
Return type

PySide6.QtGui.QWindow

Returns the QWindow that receives events tied to focus, such as key events.

PySide6.QtGui.QGuiApplication.focusWindowChanged(focusWindow)
Parameters

focusWindowPySide6.QtGui.QWindow

static PySide6.QtGui.QGuiApplication.font()
Return type

PySide6.QtGui.QFont

Returns the default application font.

See also

setFont()

PySide6.QtGui.QGuiApplication.fontChanged(font)
Parameters

fontPySide6.QtGui.QFont

Note

This function is deprecated.

PySide6.QtGui.QGuiApplication.fontDatabaseChanged()
static PySide6.QtGui.QGuiApplication.highDpiScaleFactorRoundingPolicy()
Return type

HighDpiScaleFactorRoundingPolicy

Returns the high-DPI scale factor rounding policy.

static PySide6.QtGui.QGuiApplication.inputMethod()
Return type

PySide6.QtGui.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.

See also

QInputMethod

static PySide6.QtGui.QGuiApplication.isLeftToRight()
Return type

bool

Returns true if the application’s layout direction is LeftToRight ; otherwise returns false.

static PySide6.QtGui.QGuiApplication.isRightToLeft()
Return type

bool

Returns true if the application’s layout direction is RightToLeft ; otherwise returns false.

PySide6.QtGui.QGuiApplication.isSavingSession()
Return type

bool

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

PySide6.QtGui.QGuiApplication.isSessionRestored()
Return type

bool

Returns true if the application has been restored from an earlier session; otherwise returns false.

static PySide6.QtGui.QGuiApplication.keyboardModifiers()
Return type

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 ( KeyPress and KeyRelease events).

It should be noted this may not reflect the actual keys held on the input device at the time of calling but rather the modifiers as last reported in one of the above events. If no keys are being held NoModifier is returned.

PySide6.QtGui.QGuiApplication.lastWindowClosed()
static PySide6.QtGui.QGuiApplication.layoutDirection()
Return type

LayoutDirection

This property holds the default layout direction for this application.

On system start-up, the default layout direction depends on the application’s language.

The notifier signal was introduced in Qt 5.4.

See also

layoutDirection isLeftToRight() isRightToLeft()

PySide6.QtGui.QGuiApplication.layoutDirectionChanged(direction)
Parameters

directionLayoutDirection

static PySide6.QtGui.QGuiApplication.modalWindow()
Return type

PySide6.QtGui.QWindow

Returns the most recently shown modal window. If no modal windows are visible, this function returns zero.

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.

See also

WindowModality setModality()

static PySide6.QtGui.QGuiApplication.mouseButtons()
Return type

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 events).

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 is returned.

static PySide6.QtGui.QGuiApplication.overrideCursor()
Return type

PySide6.QtGui.QCursor

Returns the active application override cursor.

This function returns None if no application cursor has been defined (i.e. the internal cursor stack is empty).

static PySide6.QtGui.QGuiApplication.palette()
Return type

PySide6.QtGui.QPalette

Returns the current application palette.

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

See also

setPalette()

PySide6.QtGui.QGuiApplication.paletteChanged(pal)
Parameters

palPySide6.QtGui.QPalette

Note

This function is deprecated.

static PySide6.QtGui.QGuiApplication.platformName()
Return type

str

This property holds The name of the underlying platform plugin..

The QPA platform plugins are located in qtbase\src\plugins\platforms. At the time of writing, the following platform plugin names are supported:

  • android

  • cocoa is a platform plugin for macOS.

  • directfb

  • eglfs is a platform plugin for running Qt5 applications on top of EGL and OpenGL ES 2.0 without an actual windowing system (like X11 or Wayland). For more information, see EGLFS.

  • ios (also used for tvOS)

  • linuxfb writes directly to the framebuffer. For more information, see LinuxFB.

  • minimal is provided as an examples for developers who want to write their own platform plugins. However, you can use the plugin to run GUI applications in environments without a GUI, such as servers.

  • minimalegl is an example plugin.

  • offscreen

  • qnx

  • windows

  • wayland is a platform plugin for modern Linux desktops and some embedded systems.

  • xcb is the X11 plugin used on regular desktop Linux platforms.

For more information about the platform plugins for embedded Linux devices, see Qt for Embedded Linux.

static PySide6.QtGui.QGuiApplication.primaryScreen()
Return type

PySide6.QtGui.QScreen

This property holds the primary (or default) screen of the application..

This will be the screen where QWindows are initially shown, unless otherwise specified.

The signal was introduced in Qt 5.6.

See also

screens()

PySide6.QtGui.QGuiApplication.primaryScreenChanged(screen)
Parameters

screenPySide6.QtGui.QScreen

static PySide6.QtGui.QGuiApplication.queryKeyboardModifiers()
Return type

KeyboardModifiers

Queries and returns the state of the modifier keys on the keyboard. Unlike keyboardModifiers , this method returns the actual keys held on the input device at the time of calling the method.

It does not rely on the keypress events having been received by this process, which makes it possible to check the modifiers while moving a window, for instance. Note that in most cases, you should use 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 PySide6.QtGui.QGuiApplication.quitOnLastWindowClosed()
Return type

bool

This property holds whether the application implicitly quits when the last window is closed..

The default is true.

If this property is true, the applications quits when the last visible primary window (i.e. window with no parent) is closed.

See also

quit() close()

static PySide6.QtGui.QGuiApplication.restoreOverrideCursor()

Undoes the last setOverrideCursor() .

If setOverrideCursor() has been called twice, calling will activate the first cursor set. Calling this function a second time restores the original widgets’ cursors.

PySide6.QtGui.QGuiApplication.saveStateRequest(sessionManager)
Parameters

sessionManagerPySide6.QtGui.QSessionManager

PySide6.QtGui.QGuiApplication.screenAdded(screen)
Parameters

screenPySide6.QtGui.QScreen

static PySide6.QtGui.QGuiApplication.screenAt(point)
Parameters

pointPySide6.QtCore.QPoint

Return type

PySide6.QtGui.QScreen

Returns the screen at point, or None if outside of any screen.

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 virtualSiblingAt() .

PySide6.QtGui.QGuiApplication.screenRemoved(screen)
Parameters

screenPySide6.QtGui.QScreen

static PySide6.QtGui.QGuiApplication.screens()
Return type

Returns a list of all the screens associated with the windowing system the application is connected to.

PySide6.QtGui.QGuiApplication.sessionId()
Return type

str

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.

PySide6.QtGui.QGuiApplication.sessionKey()
Return type

str

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 PySide6.QtGui.QGuiApplication.setApplicationDisplayName(name)
Parameters

name – str

This property holds the user-visible name of this application.

This name is shown to the user, for instance in window titles. It can be translated, if necessary.

If not set, the application display name defaults to the application name.

See also

applicationName

static PySide6.QtGui.QGuiApplication.setDesktopFileName(name)
Parameters

name – str

This property holds the base name of the desktop entry for this application.

This is the file name, without the full path, of the desktop entry that represents this application according to the freedesktop desktop entry specification.

This property gives a precise indication of what desktop entry represents the application and it is needed by the windowing system to retrieve such information without resorting to imprecise heuristics.

The latest version of the freedesktop desktop entry specification can be obtained here .

static PySide6.QtGui.QGuiApplication.setDesktopSettingsAware(on)
Parameters

on – bool

Sets whether Qt should use the system’s standard colors, fonts, etc., to on. By default, this is true.

This function must be called before creating the QGuiApplication object, like this:

if __name__ == "__main__":

    QApplication.setDesktopSettingsAware(False)
    app = QApplication([])
    # ...
    sys.exit(app.exec())
static PySide6.QtGui.QGuiApplication.setFont(arg__1)
Parameters

arg__1PySide6.QtGui.QFont

Changes the default application font to font.

See also

font()

static PySide6.QtGui.QGuiApplication.setHighDpiScaleFactorRoundingPolicy(policy)
Parameters

policyHighDpiScaleFactorRoundingPolicy

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 HighDpiScaleFactorRoundingPolicy enum for a complete list of all options.

This function must be called before creating the application object. The highDpiScaleFactorRoundingPolicy() accessor will reflect the environment, if set.

The default value is PassThrough .

static PySide6.QtGui.QGuiApplication.setLayoutDirection(direction)
Parameters

directionLayoutDirection

This property holds the default layout direction for this application.

On system start-up, the default layout direction depends on the application’s language.

The notifier signal was introduced in Qt 5.4.

See also

layoutDirection isLeftToRight() isRightToLeft()

static PySide6.QtGui.QGuiApplication.setOverrideCursor(arg__1)
Parameters

arg__1PySide6.QtGui.QCursor

Sets the application override cursor to 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 currently active application override cursor.

Every must eventually be followed by a corresponding restoreOverrideCursor() , otherwise the stack will never be emptied.

Example:

QGuiApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
calculateHugeMandelbrot() # lunch time...
QGuiApplication.restoreOverrideCursor()
static PySide6.QtGui.QGuiApplication.setPalette(pal)
Parameters

palPySide6.QtGui.QPalette

Changes the application palette to pal.

The color roles from this palette are combined with the system’s platform theme to form the application’s final palette.

See also

palette()

static PySide6.QtGui.QGuiApplication.setQuitOnLastWindowClosed(quit)
Parameters

quit – bool

This property holds whether the application implicitly quits when the last window is closed..

The default is true.

If this property is true, the applications quits when the last visible primary window (i.e. window with no parent) is closed.

See also

quit() close()

static PySide6.QtGui.QGuiApplication.setWindowIcon(icon)
Parameters

iconPySide6.QtGui.QIcon

This property holds the default window icon.

See also

setIcon() Setting the Application Icon

static PySide6.QtGui.QGuiApplication.styleHints()
Return type

PySide6.QtGui.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.

See also

QStyleHints

static PySide6.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 PySide6.QtGui.QGuiApplication.topLevelAt(pos)
Parameters

posPySide6.QtCore.QPoint

Return type

PySide6.QtGui.QWindow

Returns the top level window at the given position pos, if any.

static PySide6.QtGui.QGuiApplication.topLevelWindows()
Return type

Returns a list of the top-level windows in the application.

See also

allWindows()

static PySide6.QtGui.QGuiApplication.windowIcon()
Return type

PySide6.QtGui.QIcon

This property holds the default window icon.

See also

setIcon() Setting the Application Icon