PySide6.QtGui.QGuiApplication¶
- class QGuiApplication¶
The
QGuiApplication
class manages the GUI application’s control flow and main settings. More…Inherited by:
QApplication
Synopsis¶
Properties¶
applicationDisplayNameᅟ
- The user-visible name of this applicationdesktopFileNameᅟ
- The base name of the desktop entry for this applicationlayoutDirectionᅟ
- The default layout direction for this applicationplatformNameᅟ
- Name of the underlying platform pluginprimaryScreenᅟ
- The primary (or default) screen of the applicationquitOnLastWindowClosedᅟ
- Whether the application implicitly quits when the last window is closedwindowIconᅟ
- The default window icon
Methods¶
def
__init__()
def
exec_()
def
sessionId()
def
sessionKey()
def
setBadgeNumber()
Signals¶
def
fontChanged()
def
paletteChanged()
def
screenAdded()
def
screenRemoved()
Static functions¶
def
allWindows()
def
clipboard()
def
focusObject()
def
focusWindow()
def
font()
def
inputMethod()
def
isLeftToRight()
def
isRightToLeft()
def
modalWindow()
def
mouseButtons()
def
overrideCursor()
def
palette()
def
platformName()
def
primaryScreen()
def
screenAt()
def
screens()
def
setFont()
def
setPalette()
def
setWindowIcon()
def
styleHints()
def
sync()
def
topLevelAt()
def
windowIcon()
Note
This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE
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 oftopLevelWindows()
, 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()
andcommitDataRequest()
andsaveStateRequest()
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 ofargv
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
QCoreApplicationQAbstractEventDispatcherQEventLoop
Note
Properties can be used directly when
from __feature__ import true_property
is used or via accessor functions otherwise.- property applicationDisplayNameᅟ: 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
- Access functions:
- property desktopFileNameᅟ: str¶
This property holds the base name of the desktop entry for this application.
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.
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 .
- Access functions:
- property layoutDirectionᅟ: Qt.LayoutDirection¶
This property holds the default layout direction for this application.
On system start-up, or when the direction is explicitly set to Qt::LayoutDirectionAuto, the default layout direction depends on the application’s language.
The notifier signal was introduced in Qt 5.4.
See also
- Access functions:
- property platformNameᅟ: 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 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.
Note
Calling this function without a
QGuiApplication
will return the default platform name, if available. The default platform name is not affected by the-platform
command line option, or theQT_QPA_PLATFORM
environment variable.For more information about the platform plugins for embedded Linux devices, see Qt for Embedded Linux.
- Access functions:
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 primaryScreenChanged signal was introduced in Qt 5.6.
See also
- Access functions:
- property quitOnLastWindowClosedᅟ: 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 application will attempt to quit when the last visible primary window (i.e. top level window with no transient parent) is closed.Note that attempting a quit may not necessarily result in the application quitting, for example if there still are active QEventLoopLocker instances, or the QEvent::Quit event is ignored.
See also
- Access functions:
This property holds the default window icon.
See also
setIcon()
Setting the Application Icon
- Access functions:
- __init__()¶
- __init__(arg__1)
- Parameters:
arg__1 – list of strings
Returns a list of all the windows in the application.
The list is empty if there are no windows.
See also
- static applicationDisplayName()¶
- Return type:
str
See also
Getter of property
applicationDisplayNameᅟ
.- applicationDisplayNameChanged()¶
Notification signal of property
applicationDisplayNameᅟ
.- static applicationState()¶
- Return type:
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.
- applicationStateChanged(state)¶
- Parameters:
state –
ApplicationState
This signal is emitted when the
state
of the application changes.See also
- static clipboard()¶
- Return type:
- commitDataRequest(sessionManager)¶
- Parameters:
sessionManager –
QSessionManager
This signal deals with session management. It is emitted when the
QSessionManager
wants the application to commit all its data.Usually this means saving all open files, after getting permission from the user. Furthermore you may want to provide a means by which the user can cancel the shutdown.
You should not exit the application within this signal. Instead, the session manager may or may not do this afterwards, depending on the context.
Warning
Within this signal, no user interaction is possible, unless you ask the
manager
for explicit permission. SeeallowsInteraction()
andallowsErrorInteraction()
for details and example usage.Note
You should use Qt::DirectConnection when connecting to this signal.
See also
isSessionRestored()
sessionId()
saveStateRequest()
Session Management
- static desktopFileName()¶
- Return type:
str
See also
Getter of property
desktopFileNameᅟ
.- static desktopSettingsAware()¶
- Return type:
bool
- 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.See also
- exec_()¶
- Return type:
int
Returns the QObject in currently active window that will be final receiver of events tied to focus, such as key events.
This signal is emitted when final receiver of events tied to focus is changed.
focusObject
is the new receiver.See also
Returns the
QWindow
that receives events tied to focus, such as key events.See also
This signal is emitted when the focused window changes.
focusWindow
is the new focused window.See also
Handle QEvent::ApplicationFontChange instead.
This signal is emitted when the
font
of the application changes. Use QEvent::ApplicationFontChanged instead.See also
- 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.
- static highDpiScaleFactorRoundingPolicy()¶
- Return type:
- static inputMethod()¶
- Return type:
- static isLeftToRight()¶
- Return type:
bool
Returns
true
if the application’s layout direction is Qt::LeftToRight; otherwise returnsfalse
.See also
- static isRightToLeft()¶
- Return type:
bool
Returns
true
if the application’s layout direction is Qt::RightToLeft; otherwise returnsfalse
.See also
- isSavingSession()¶
- Return type:
bool
Returns
true
if the application is currently saving the session; otherwise returnsfalse
.This is
true
whencommitDataRequest()
andsaveStateRequest()
are emitted, but also when the windows are closed afterwards by session management.- isSessionRestored()¶
- Return type:
bool
Returns
true
if the application has been restored from an earlier session; otherwise returnsfalse
.- static keyboardModifiers()¶
- Return type:
Combination of
KeyboardModifier
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 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 Qt::NoModifier is returned.
See also
- lastWindowClosed()¶
This signal is emitted from
exec()
when the last visible primary window (i.e. top level window with no transient parent) is closed.By default,
QGuiApplication
quits after this signal is emitted. This feature can be turned off by settingquitOnLastWindowClosed
tofalse
.See also
- static layoutDirection()¶
- Return type:
See also
Getter of property
layoutDirectionᅟ
.- layoutDirectionChanged(direction)¶
- Parameters:
direction –
LayoutDirection
Notification signal of property
layoutDirectionᅟ
.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 Qt::WindowModal or Qt::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
- static mouseButtons()¶
- Return type:
Combination of
MouseButton
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 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 Qt::NoButton is returned.
See also
- nativeInterface()¶
- Return type:
object
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).Handle QEvent::ApplicationPaletteChange instead.
This signal is emitted when the
palette
of the application changes. Use QEvent::ApplicationPaletteChanged instead.See also
- static platformFunction(function)¶
- Parameters:
function –
QByteArray
- Return type:
QFunctionPointer
- static platformName()¶
- Return type:
str
Getter of property
platformNameᅟ
.Getter of property
primaryScreenᅟ
.Notification signal of property
primaryScreenᅟ
.- static queryKeyboardModifiers()¶
- Return type:
Combination of
KeyboardModifier
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.See also
- static quitOnLastWindowClosed()¶
- Return type:
bool
See also
Getter of property
quitOnLastWindowClosedᅟ
.- static restoreOverrideCursor()¶
Undoes the last
setOverrideCursor()
.If
setOverrideCursor()
has been called twice, calling restoreOverrideCursor() will activate the first cursor set. Calling this function a second time restores the original widgets’ cursors.See also
- saveStateRequest(sessionManager)¶
- Parameters:
sessionManager –
QSessionManager
This signal deals with session management. It is invoked when the
session manager
wants the application to preserve its state for a future session.For example, a text editor would create a temporary file that includes the current contents of its edit buffers, the location of the cursor and other aspects of the current editing session.
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.
Warning
Within this signal, no user interaction is possible, unless you ask the
manager
for explicit permission. SeeallowsInteraction()
andallowsErrorInteraction()
for details.Note
You should use Qt::DirectConnection when connecting to this signal.
See also
isSessionRestored()
sessionId()
commitDataRequest()
Session Management
This signal is emitted whenever a new screen
screen
has been added to the system.See also
Returns the screen at
point
, orNone
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 windowQWidget::windowHandle()->screen()
), usevirtualSiblingAt()
.This signal is emitted whenever a
screen
is removed from the system. It provides an opportunity to manage the windows on the screen before Qt falls back to moving them to the primary screen.See also
Returns a list of all the screens associated with the windowing system the application is connected to.
- 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.
- 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 setApplicationDisplayName(name)¶
- Parameters:
name – str
See also
Setter of property
applicationDisplayNameᅟ
.- setBadgeNumber(number)¶
- Parameters:
number – int
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.
See also
applicationName
- static setDesktopFileName(name)¶
- Parameters:
name – str
See also
Setter of property
desktopFileNameᅟ
.- static setDesktopSettingsAware(on)¶
- Parameters:
on – bool
- static setHighDpiScaleFactorRoundingPolicy(policy)¶
- Parameters:
policy –
HighDpiScaleFactorRoundingPolicy
- static setLayoutDirection(direction)¶
- Parameters:
direction –
LayoutDirection
See also
Setter of property
layoutDirectionᅟ
.- static setOverrideCursor(arg__1)¶
- Parameters:
arg__1 –
QCursor
- Return type:
QtGuiHelper::QOverrideCursorGuard*
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
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 setOverrideCursor() is called.Application cursors are stored on an internal stack. setOverrideCursor() pushes the cursor onto the stack, and
restoreOverrideCursor()
pops the active cursor off the stack. changeOverrideCursor() changes the currently active application override cursor.Every setOverrideCursor() 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()
See also
overrideCursor()
restoreOverrideCursor()
setCursor()
- static setQuitOnLastWindowClosed(quit)¶
- Parameters:
quit – bool
See also
Setter of property
quitOnLastWindowClosedᅟ
.Setter of property
windowIconᅟ
.- static styleHints()¶
- Return type:
- static sync()¶
Returns the top level window at the given position
pos
, if any.Returns a list of the top-level windows in the application.
See also
- static windowIcon()¶
- Return type:
See also
Getter of property
windowIconᅟ
.