QApplication#
The QApplication
class manages the GUI application’s control flow and main settings. More…
Synopsis#
Properties#
autoSipEnabled
- Toggles automatic SIP (software input panel) visibilitycursorFlashTime
- The text cursor’s flash (blink) time in millisecondsdoubleClickInterval
- The time limit in milliseconds that distinguishes a double click from two consecutive mouse clickskeyboardInputInterval
- The time limit in milliseconds that distinguishes a key press from two consecutive key pressesstartDragDistance
- The minimum distance required for a drag and drop operation to startstartDragTime
- The time in milliseconds that a mouse button must be held down before a drag and drop operation will beginstyleSheet
- The application style sheetwheelScrollLines
- The number of lines to scroll a widget, when the mouse wheel is rotated
Functions#
def
autoSipEnabled
()def
exec_
()def
styleSheet
()
Slots#
def
setAutoSipEnabled
(enabled)def
setStyleSheet
(sheet)
Signals#
def
focusChanged
(old, now)
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)
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#
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
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:
QCoreApplication* createApplication(int argc, char *argv[]) for i in range(1, argc): if not qstrcmp(argv[i], "-no-gui"): return QCoreApplication(argc, argv) return QApplication(argc, argv) if __name__ == "__main__": app = QScopedPointer(createApplication(argc, argv)) if QApplication(app.data()): # start GUI version... else: # start non-GUI version... sys.exit(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
widgetAt()
, get a list oftopLevelWidgets()
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()
,widgetAt()
.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
Note
Properties can be used directly when from __feature__ import true_property
is used or via accessor functions otherwise.
- property PᅟySide6.QtWidgets.QApplication.autoSipEnabled: bool#
This property holds toggles automatic SIP (software input panel) visibility.
Set this property to true
to automatically display the SIP when entering widgets that accept keyboard input. This property only affects widgets with the WA_InputMethodEnabled attribute set, and is typically used to launch a virtual keyboard on devices which have very few or no keys.
The property only has an effect on platforms that use software input panels.
The default is platform dependent.
- Access functions:
setAutoSipEnabled
(enabled)
- property PᅟySide6.QtWidgets.QApplication.cursorFlashTime: int#
This property holds the text cursor’s flash (blink) time in milliseconds.
The flash time is the time required to display, invert and restore the caret display. Usually the text cursor is displayed for half the cursor flash time, then hidden for the same amount of time, but this may vary.
The default value on X11 is 1000 milliseconds. On Windows, the Control Panel value is used and setting this property sets the cursor flash time for all applications.
We recommend that widgets do not cache this value as it may change at any time if the user changes the global desktop settings.
Note
This property may hold a negative value, for instance if cursor blinking is disabled.
- Access functions:
setCursorFlashTime
(arg__1)
- property PᅟySide6.QtWidgets.QApplication.doubleClickInterval: int#
This property holds the time limit in milliseconds that distinguishes a double click from two consecutive mouse clicks.
The default value on X11 is 400 milliseconds. On Windows and Mac OS, the operating system’s value is used.
- Access functions:
setDoubleClickInterval
(arg__1)
- property PᅟySide6.QtWidgets.QApplication.keyboardInputInterval: int#
This property holds the time limit in milliseconds that distinguishes a key press from two consecutive key presses.
The default value on X11 is 400 milliseconds. On Windows and Mac OS, the operating system’s value is used.
- Access functions:
setKeyboardInputInterval
(arg__1)
- property PᅟySide6.QtWidgets.QApplication.startDragDistance: int#
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
This property holds the minimum distance required for a drag and drop operation to start..
If you support drag and drop in your application, and want to start a drag and drop operation after the user has moved the cursor a certain distance with a button held down, you should use this property’s value as the minimum distance required.
For example, if the mouse position of the click is stored in startPos
and the current position (e.g. in the mouse move event) is currentPos
, you can find out if a drag should be started with code like this:
if ((startPos - currentPos).manhattanLength() >= QApplication.startDragDistance()) startTheDrag()
Qt uses this value internally, e.g. in QFileDialog
.
The default value (if the platform doesn’t provide a different default) is 10 pixels.
See also
startDragTime()
manhattanLength()
Drag and Drop
- Access functions:
- property PᅟySide6.QtWidgets.QApplication.startDragTime: int#
This property holds the time in milliseconds that a mouse button must be held down before a drag and drop operation will begin.
If you support drag and drop in your application, and want to start a drag and drop operation after the user has held down a mouse button for a certain amount of time, you should use this property’s value as the delay.
Qt also uses this delay internally, e.g. in QTextEdit
and QLineEdit
, for starting a drag.
The default value is 500 ms.
See also
- Access functions:
setStartDragTime
(ms)
- property PᅟySide6.QtWidgets.QApplication.styleSheet: str#
This property holds the application style sheet.
By default, this property returns an empty string unless the user specifies the -stylesheet
option on the command line when running the application.
See also
- Access functions:
styleSheet
()setStyleSheet
(sheet)
- property PᅟySide6.QtWidgets.QApplication.wheelScrollLines: int#
This property holds the number of lines to scroll a widget, when the mouse wheel is rotated..
If the value exceeds the widget’s number of visible lines, the widget should interpret the scroll operation as a single page up or page down. If the widget is an item view class
, then the result of scrolling one line depends on the setting of the widget’s scroll mode
. Scroll one line can mean scroll one item
or scroll one pixel
.
By default, this property has a value of 3.
See also
wheelScrollLines()
- Access functions:
setWheelScrollLines
(arg__1)
- 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 activeWindow() even if there is no focusWidget()
, for example if no widget in that window accepts key events.
- static PySide6.QtWidgets.QApplication.alert(widget[, duration=0])#
- Parameters:
widget –
PySide6.QtWidgets.QWidget
duration – int
Causes an alert to be shown for widget
if the window is not the active window. The alert is shown for msec
milliseconds. If msec
is zero (the default), then the alert is shown indefinitely until the window becomes active again.
Currently this function does nothing on Qt for Embedded Linux.
On macOS, this works more at the application level and will cause the application icon to bounce in the dock.
On Windows, this causes the window’s taskbar entry to flash for a time. If msec
is zero, the flashing will stop and the taskbar entry will turn a different color (currently orange).
On X11, this will cause the window to be marked as “demands attention”, the window must not be hidden (i.e. not have hide() called on it, but be visible in some sort of way) in order for this to work.
- static PySide6.QtWidgets.QApplication.allWidgets()#
- Return type:
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
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(): allWidgets = QApplication.allWidgets() for widget in allWidgets: widget.update()See also
- PySide6.QtWidgets.QApplication.autoSipEnabled()#
- Return type:
bool
See also
Getter of property autoSipEnabled
.
- static PySide6.QtWidgets.QApplication.beep()#
Sounds the bell, using the default volume and sound. The function is not available in Qt for Embedded Linux.
- 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
Getter of property cursorFlashTime
.
- static PySide6.QtWidgets.QApplication.doubleClickInterval()#
- Return type:
int
See also
Getter of property doubleClickInterval
.
- PySide6.QtWidgets.QApplication.exec_()#
- Return type:
int
- PySide6.QtWidgets.QApplication.focusChanged(old, now)#
- Parameters:
This signal is emitted when the widget that has keyboard focus changed from old
to now
, i.e., because the user pressed the tab-key, clicked into a widget or changed the active window. Both old
and now
can be None
.
The signal is emitted after both widget have been notified about the change through QFocusEvent
.
See also
setFocus()
clearFocus()
FocusReason
- 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.
See also
font()
setFont()
fontMetrics()
fontMetrics()
- static PySide6.QtWidgets.QApplication.isEffectEnabled(arg__1)#
- Parameters:
arg__1 –
UIEffect
- Return type:
bool
Returns true
if effect
is enabled; otherwise returns false
.
By default, Qt will try to use the desktop settings. To prevent this, call setDesktopSettingsAware(false).
Note
All effects are disabled on screens running at less than 16-bit color depth.
See also
setEffectEnabled()
UIEffect
- static PySide6.QtWidgets.QApplication.keyboardInputInterval()#
- Return type:
int
See also
Getter of property keyboardInputInterval
.
- static PySide6.QtWidgets.QApplication.palette(arg__1)#
- Parameters:
arg__1 –
PySide6.QtWidgets.QWidget
- Return type:
If a widget
is passed, the default palette for the widget’s class is returned. This may or may not be the application palette. In most cases there is no special palette for certain types of widgets, but one notable exception is the popup menu under Windows, if the user has defined a special background color for menus in the display settings.
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:
Note
This function is deprecated.
Use activateWindow()
instead.
Sets the active window to the active
widget in response to a system event. The function is called from the platform specific event handlers.
Warning
This function does not set the keyboard focus to the active widget. Call activateWindow()
instead.
It sets the activeWindow()
and focusWidget()
attributes and sends proper WindowActivate
/ WindowDeactivate
and FocusIn
/ FocusOut
events to all appropriate widgets. The window will then be painted in active state (e.g. cursors in line edits will blink), and it will have tool tips enabled.
See also
- PySide6.QtWidgets.QApplication.setAutoSipEnabled(enabled)#
- Parameters:
enabled – bool
See also
Setter of property autoSipEnabled
.
- static PySide6.QtWidgets.QApplication.setCursorFlashTime(arg__1)#
- Parameters:
arg__1 – int
See also
Setter of property cursorFlashTime
.
- static PySide6.QtWidgets.QApplication.setDoubleClickInterval(arg__1)#
- Parameters:
arg__1 – int
See also
Setter of property doubleClickInterval
.
- static PySide6.QtWidgets.QApplication.setEffectEnabled(arg__1[, enable=true])#
- Parameters:
arg__1 –
UIEffect
enable – bool
Enables the UI effect effect
if enable
is true, otherwise the effect will not be used.
Note
All effects are disabled on screens running at less than 16-bit color depth.
See also
isEffectEnabled()
UIEffect
setDesktopSettingsAware()
- 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
Setter of property keyboardInputInterval
.
- 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
Setter of property startDragDistance
.
- static PySide6.QtWidgets.QApplication.setStartDragTime(ms)#
- Parameters:
ms – int
See also
Setter of property startDragTime
.
- static PySide6.QtWidgets.QApplication.setStyle(arg__1)#
- Parameters:
arg__1 –
PySide6.QtWidgets.QStyle
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
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(QStyleFactory.create("Fusion"))
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:
This is an overloaded function.
Requests a QStyle
object for style
from the QStyleFactory
.
The string must be one of the keys()
, typically one of “windows”, “windowsvista”, “fusion”, or “macos”. Style names are case insensitive.
Returns None
if an unknown style
is passed, otherwise the QStyle
object returned is set as the application’s GUI style.
Warning
To ensure that the application’s style is set correctly, it is best to call this function before the QApplication
constructor, if possible.
- PySide6.QtWidgets.QApplication.setStyleSheet(sheet)#
- Parameters:
sheet – str
See also
Setter of property styleSheet
.
- static PySide6.QtWidgets.QApplication.setWheelScrollLines(arg__1)#
- Parameters:
arg__1 – int
See also
Setter of property wheelScrollLines
.
- static PySide6.QtWidgets.QApplication.startDragDistance()#
- Return type:
int
See also
Getter of property startDragDistance
.
- static PySide6.QtWidgets.QApplication.startDragTime()#
- Return type:
int
See also
Getter of property startDragTime
.
- static PySide6.QtWidgets.QApplication.style()#
- Return type:
Returns the application’s style object.
See also
- PySide6.QtWidgets.QApplication.styleSheet()#
- Return type:
str
See also
Getter of property styleSheet
.
- static PySide6.QtWidgets.QApplication.topLevelAt(x, y)#
- Parameters:
x – int
y – int
- Return type:
This is an overloaded function.
Returns the top-level widget at the point (x
, y
); returns 0 if there is no such widget.
- static PySide6.QtWidgets.QApplication.topLevelWidgets()#
- Return type:
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
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(): topLevelWidgets = QApplication.topLevelWidgets() for widget in topLevelWidgets: if widget.isHidden(): widget.show()See also
- static PySide6.QtWidgets.QApplication.wheelScrollLines()#
- Return type:
int
See also
Getter of property wheelScrollLines
.
- static PySide6.QtWidgets.QApplication.widgetAt(p)#
- Parameters:
- Return type:
Returns the widget at global screen position point
, or None
if there is no Qt widget there.
This function can be slow.
See also
pos()
grabMouse()
grabKeyboard()
- static PySide6.QtWidgets.QApplication.widgetAt(x, y)
- Parameters:
x – int
y – int
- Return type:
This is an overloaded function.
Returns the widget at global screen position (x
, y
), or None
if there is no Qt widget there.