QApplication¶
The QApplication
class manages the GUI application’s control flow and main settings. More…

Synopsis¶
Functions¶
def
autoSipEnabled
()def
focusChanged
(old, now)def
setAutoSipEnabled
(enabled)def
setStyleSheet
(sheet)def
styleSheet
()
Static functions¶
def
aboutQt
()def
activeModalWidget
()def
activePopupWidget
()def
activeWindow
()def
alert
(widget[, duration=0])def
allWidgets
()def
beep
()def
closeAllWindows
()def
cursorFlashTime
()def
doubleClickInterval
()def
focusWidget
()def
font
(arg__1)def
font
(className)def
fontMetrics
()def
isEffectEnabled
(arg__1)def
keyboardInputInterval
()def
palette
(arg__1)def
palette
(className)def
setActiveWindow
(act)def
setCursorFlashTime
(arg__1)def
setDoubleClickInterval
(arg__1)def
setEffectEnabled
(arg__1[, enable=true])def
setFont
(arg__1[, className=None])def
setKeyboardInputInterval
(arg__1)def
setPalette
(arg__1[, className=None])def
setStartDragDistance
(l)def
setStartDragTime
(ms)def
setStyle
(arg__1)def
setStyle
(arg__1)def
setWheelScrollLines
(arg__1)def
startDragDistance
()def
startDragTime
()def
style
()def
topLevelAt
(x, y)def
topLevelWidgets
()def
wheelScrollLines
()def
widgetAt
(p)def
widgetAt
(x, y)
Detailed Description¶
QApplication
specializes QGuiApplication
with some functionality needed for QWidget -based applications. It handles widget specific initialization, finalization.
For any GUI application using Qt, there is precisely one QApplication
object, no matter whether the application has 0, 1, 2 or more windows at any given time. For non- QWidget based Qt applications, use QGuiApplication
instead, as it does not depend on the QtWidgets library.
Some GUI applications provide a special batch mode ie. provide command line arguments for executing tasks without manual intervention. In such non-GUI mode, it is often sufficient to instantiate a plain QCoreApplication
to avoid unnecessarily initializing resources needed for a graphical user interface. The following example shows how to dynamically create an appropriate type of application instance:
def main(): useGUI = not '-no-gui' in sys.argv app = QApplication(sys.argv) if useGUI else QCoreApplication(sys.argv) ... return app.exec_()
The QApplication
object is accessible through the instance()
function that returns a pointer equivalent to the global qApp
pointer.
QApplication
‘s main areas of responsibility are:
It initializes the application with the user’s desktop settings such as
palette()
,font()
anddoubleClickInterval()
. 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. By using
sendEvent()
andpostEvent()
you can send your own events to widgets.It parses common command line arguments and sets its internal state accordingly. See the
constructor documentation
below for more details.It defines the application’s look and feel, which is encapsulated in a
QStyle
object. This can be changed at runtime withsetStyle()
.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 widget is at a certain position using , get a list of
topLevelWidgets()
andcloseAllWindows()
, etc.It manages the application’s mouse cursor handling, see
setOverrideCursor()
Since the QApplication
object does so much initialization, it must be created before any other objects related to the user interface are created. QApplication
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()
,cursorFlashTime()
,setCursorFlashTime()
,doubleClickInterval()
,setDoubleClickInterval()
,setKeyboardInputInterval()
,wheelScrollLines()
,setWheelScrollLines()
,palette()
,setPalette()
,font()
,setFont()
,fontMetrics()
.Event handling
exec()
,processEvents()
,exit()
,quit()
.sendEvent()
,postEvent()
,sendPostedEvents()
,removePostedEvents()
,notify()
.GUI Styles
style()
,setStyle()
.Text handling
installTranslator()
,removeTranslator()
translate()
.Widgets
allWidgets()
,topLevelWidgets()
,activePopupWidget()
,activeModalWidget()
,clipboard()
,focusWidget()
,activeWindow()
, .Advanced cursor handling
overrideCursor()
,setOverrideCursor()
,restoreOverrideCursor()
.Miscellaneous
closeAllWindows()
,startingUp()
,closingDown()
.See also
QCoreApplication
QAbstractEventDispatcher
QEventLoop
QSettings
-
class
PySide6.QtWidgets.
QApplication
¶ PySide6.QtWidgets.QApplication(arg__1)
- Parameters
arg__1 – list of strings
-
static
PySide6.QtWidgets.QApplication.
aboutQt
()¶
Displays a simple message box about Qt. The message includes the version number of Qt being used by the application.
This is useful for inclusion in the Help menu of an application, as shown in the Menus example.
This function is a convenience slot for aboutQt()
.
-
static
PySide6.QtWidgets.QApplication.
activeModalWidget
()¶ - Return type
Returns the active modal widget.
A modal widget is a special top-level widget which is a subclass of QDialog
that specifies the modal parameter of the constructor as true. A modal widget must be closed before the user can continue with other parts of the program.
Modal widgets are organized in a stack. This function returns the active modal widget at the top of the stack.
See also
-
static
PySide6.QtWidgets.QApplication.
activePopupWidget
()¶ - Return type
Returns the active popup widget.
A popup widget is a special top-level widget that sets the Qt::WType_Popup
widget flag, e.g. the QMenu
widget. When the application opens a popup widget, all events are sent to the popup. Normal widgets and modal widgets cannot be accessed before the popup widget is closed.
Only other popup widgets may be opened when a popup widget is shown. The popup widgets are organized in a stack. This function returns the active popup widget at the top of the stack.
See also
-
static
PySide6.QtWidgets.QApplication.
activeWindow
()¶ - Return type
Returns the application top-level window that has the keyboard input focus, or None
if no application window has the focus. There might be an even if there is no focusWidget()
, for example if no widget in that window accepts key events.
See also
-
static
PySide6.QtWidgets.QApplication.
alert
(widget[, duration=0])¶ - Parameters
widget –
PySide6.QtWidgets.QWidget
duration – int
-
static
PySide6.QtWidgets.QApplication.
allWidgets
()¶ - Return type
Returns a list of all the widgets in the application.
The list is empty ( isEmpty()
) if there are no widgets.
Note
Some of the widgets may be hidden.
Example:
def updateAllWidgets(): for widget in QApplication.allWidgets() widget.update()See also
-
PySide6.QtWidgets.QApplication.
autoSipEnabled
()¶ - Return type
bool
See also
-
static
PySide6.QtWidgets.QApplication.
beep
()¶
-
static
PySide6.QtWidgets.QApplication.
closeAllWindows
()¶
Closes all top-level windows.
This function is particularly useful for applications with many top-level windows.
The windows are closed in random order, until one window does not accept the close event. The application quits when the last window was successfully closed, unless quitOnLastWindowClosed
is set to false. To trigger application termination from e.g. a menu, use quit()
instead of this function.
See also
quitOnLastWindowClosed
lastWindowClosed()
close()
closeEvent()
lastWindowClosed()
quit()
topLevelWidgets()
isWindow()
-
static
PySide6.QtWidgets.QApplication.
cursorFlashTime
()¶ - Return type
int
See also
-
static
PySide6.QtWidgets.QApplication.
doubleClickInterval
()¶ - Return type
int
See also
-
PySide6.QtWidgets.QApplication.
focusChanged
(old, now)¶ - Parameters
-
static
PySide6.QtWidgets.QApplication.
focusWidget
()¶ - Return type
Returns the application widget that has the keyboard input focus, or None
if no widget in this application has the focus.
See also
-
static
PySide6.QtWidgets.QApplication.
font
(arg__1)¶ - Parameters
arg__1 –
PySide6.QtWidgets.QWidget
- Return type
This is an overloaded function.
Returns the default font for the widget
. If a default font was not registered for the widget
’s class, it returns the default font of its nearest registered superclass.
See also
-
static
PySide6.QtWidgets.QApplication.
font
(className) - Parameters
className – str
- Return type
This is an overloaded function.
Returns the font for widgets of the given className
.
-
static
PySide6.QtWidgets.QApplication.
fontMetrics
()¶ - Return type
Note
This function is deprecated.
Use the QFontMetricsF
constructor instead Returns display (screen) font metrics for the application font.
-
static
PySide6.QtWidgets.QApplication.
isEffectEnabled
(arg__1)¶ - Parameters
arg__1 –
UIEffect
- Return type
bool
-
static
PySide6.QtWidgets.QApplication.
keyboardInputInterval
()¶ - Return type
int
See also
-
static
PySide6.QtWidgets.QApplication.
palette
(arg__1)¶ - Parameters
arg__1 –
PySide6.QtWidgets.QWidget
- Return type
See also
-
static
PySide6.QtWidgets.QApplication.
palette
(className) - Parameters
className – str
- Return type
This is an overloaded function.
Returns the palette for widgets of the given className
.
See also
-
static
PySide6.QtWidgets.QApplication.
setActiveWindow
(act)¶ - Parameters
See also
-
PySide6.QtWidgets.QApplication.
setAutoSipEnabled
(enabled)¶ - Parameters
enabled – bool
See also
-
static
PySide6.QtWidgets.QApplication.
setCursorFlashTime
(arg__1)¶ - Parameters
arg__1 – int
See also
-
static
PySide6.QtWidgets.QApplication.
setDoubleClickInterval
(arg__1)¶ - Parameters
arg__1 – int
See also
-
static
PySide6.QtWidgets.QApplication.
setEffectEnabled
(arg__1[, enable=true])¶ - Parameters
arg__1 –
UIEffect
enable – bool
-
static
PySide6.QtWidgets.QApplication.
setFont
(arg__1[, className=None])¶ - Parameters
arg__1 –
PySide6.QtGui.QFont
className – str
Changes the default application font to font
. If className
is passed, the change applies only to classes that inherit className
(as reported by inherits()
).
On application start-up, the default font depends on the window system. It can vary depending on both the window system version and the locale. This function lets you override the default font; but overriding may be a bad idea because, for example, some locales need extra large fonts to support their special characters.
Warning
Do not use this function in conjunction with Qt Style Sheets . The font of an application can be customized using the “font” style sheet property. To set a bold font for all QPushButtons, set the application styleSheet()
as ” QPushButton
{ font: bold }”
See also
-
static
PySide6.QtWidgets.QApplication.
setKeyboardInputInterval
(arg__1)¶ - Parameters
arg__1 – int
See also
-
static
PySide6.QtWidgets.QApplication.
setPalette
(arg__1[, className=None])¶ - Parameters
arg__1 –
PySide6.QtGui.QPalette
className – str
Changes the application palette to palette
.
If className
is passed, the change applies only to widgets that inherit className
(as reported by inherits()
). If className
is left 0, the change affects all widgets, thus overriding any previously set class specific palettes.
The palette may be changed according to the current GUI style in polish()
.
Warning
Do not use this function in conjunction with Qt Style Sheets . When using style sheets, the palette of a widget can be customized using the “color”, “background-color”, “selection-color”, “selection-background-color” and “alternate-background-color”.
Note
Some styles do not use the palette for all drawing, for instance, if they make use of native theme engines. This is the case for the Windows Vista and macOS styles.
See also
-
static
PySide6.QtWidgets.QApplication.
setStartDragDistance
(l)¶ - Parameters
l – int
See also
-
static
PySide6.QtWidgets.QApplication.
setStartDragTime
(ms)¶ - Parameters
ms – int
See also
-
static
PySide6.QtWidgets.QApplication.
setStyle
(arg__1)¶ - Parameters
arg__1 –
PySide6.QtWidgets.QStyle
Sets the application’s GUI style to style
. Ownership of the style object is transferred to QApplication
, so QApplication
will delete the style object on application exit or when a new style is set and the old style is still the parent of the application object.
Example usage:
QApplication.setStyle(QWindowsStyle())
When switching application styles, the color palette is set back to the initial colors or the system defaults. This is necessary since certain styles have to adapt the color palette to be fully style-guide compliant.
Setting the style before a palette has been set, i.e., before creating QApplication
, will cause the application to use standardPalette()
for the palette.
Warning
Qt style sheets are currently not supported for custom QStyle
subclasses. We plan to address this in some future release.
See also
style()
QStyle
setPalette()
desktopSettingsAware()
-
static
PySide6.QtWidgets.QApplication.
setStyle
(arg__1) - Parameters
arg__1 – str
- Return type
-
PySide6.QtWidgets.QApplication.
setStyleSheet
(sheet)¶ - Parameters
sheet – str
See also
-
static
PySide6.QtWidgets.QApplication.
setWheelScrollLines
(arg__1)¶ - Parameters
arg__1 – int
See also
-
static
PySide6.QtWidgets.QApplication.
startDragDistance
()¶ - Return type
int
See also
-
static
PySide6.QtWidgets.QApplication.
startDragTime
()¶ - Return type
int
See also
-
static
PySide6.QtWidgets.QApplication.
style
()¶ - Return type
Returns the application’s style object.
See also
-
PySide6.QtWidgets.QApplication.
styleSheet
()¶ - Return type
str
See also
-
static
PySide6.QtWidgets.QApplication.
topLevelAt
(x, y)¶ - Parameters
x – int
y – int
- Return type
-
static
PySide6.QtWidgets.QApplication.
topLevelWidgets
()¶ - Return type
Returns a list of the top-level widgets (windows) in the application.
Note
Some of the top-level widgets may be hidden, for example a tooltip if no tooltip is currently shown.
Example:
def showAllHiddenTopLevelWidgets(): for widget in QApplication.topLevelWidgets(): if widget.isHidden(): widget.show()See also
allWidgets()
isHidden()
-
static
PySide6.QtWidgets.QApplication.
wheelScrollLines
()¶ - Return type
int
See also
-
static
PySide6.QtWidgets.QApplication.
widgetAt
(p)¶ - Parameters
- Return type
-
static
PySide6.QtWidgets.QApplication.
widgetAt
(x, y) - Parameters
x – int
y – int
- Return type
© 2021 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.