Skip to content

PythonQt.Qt.QApplication

QApplication

PythonQtInstanceWrapper object

Native bases: PythonQtInstanceWrapper

Supplemental documentation: Qt 5 reference:

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:

QCoreApplication* createApplication(int &argc, char *argv[])
{
    for (int i = 1; i < argc; ++i) {
        if (!qstrcmp(argv[i], "-no-gui"))
            return new QCoreApplication(argc, argv);
    }
    return new QApplication(argc, argv);
}

int main(int argc, char* argv[])
{
    QScopedPointer<QCoreApplication> app(createApplication(argc, argv));

    if (qobject_cast<QApplication *>(app.data())) {
       // start GUI version...
    } else {
       // start non-GUI version...
    }

    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() and doubleClickInterval(). 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() and postEvent() 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 with setStyle().
  • It provides localization of strings that are visible to the user via translate().
  • It provides some magical objects like the desktop() and the clipboard().
  • It knows about the application's windows. You can ask which widget is at a certain position using widgetAt(), get a list of topLevelWidgets() and closeAllWindows(), 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(), hasPendingEvents(), notify().
GUI Styles style(), setStyle().
Text handling installTranslator(), removeTranslator() translate().
Widgets allWidgets(), topLevelWidgets(), desktop(), activePopupWidget(), activeModalWidget(), clipboard(), focusWidget(), activeWindow(), widgetAt().
Advanced cursor handling overrideCursor(), setOverrideCursor(), restoreOverrideCursor().
Miscellaneous closeAllWindows(), startingUp(), closingDown().

Source: https://doc.qt.io/archives/qt-5.15/qapplication.html

Complete member index

Every captured member retains its own identity. Identical captured declaration text is linked once; this does not establish native inheritance or interchangeable objects.

Member Kind Signature Summary
ApplicationFlags attribute Any (shared captured text)
ColorSpec attribute type Convert a number or string to an integer, or return 0 if no arguments are given. (shared captured text)
CustomColor attribute Any (shared captured text)
ManyColor attribute Any (shared captured text)
NormalColor attribute Any (shared captured text)
__init__ function (self, *args: Any, **kwargs: Any) -> None Native constructor; consult class documentation for supported overloads. (shared captured text)
aboutQt function (self) -> None Displays a simple message box about Qt. (shared captured text)
aboutToQuit function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QApplication.aboutToQuit; argument details are not documented.
activeModalWidget function (self) -> Any X.activeModalWidget() -> PythonQt.QtGui.QWidget (shared captured text)
activePopupWidget function (self) -> Any X.activePopupWidget() -> PythonQt.QtGui.QWidget (shared captured text)
activeWindow function (self) -> Any X.activeWindow() -> PythonQt.QtGui.QWidget (shared captured text)
addLibraryPath function (self, arg__1: Any) -> Any (shared captured text)
alert function (self, widget: Any, duration: int) -> None X.alert(widget, duration) (shared captured text)
allWidgets function (self) -> tuple X.allWidgets() -> tuple (shared captured text)
allWindows function (self) -> tuple X.allWindows() -> tuple (shared captured text)
applicationDirPath function (self) -> str X.applicationDirPath() -> str (shared captured text)
applicationDisplayName attribute Any (shared captured text)
applicationDisplayNameChanged function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QApplication.applicationDisplayNameChanged; argument details are not documented.
applicationFilePath function (self) -> str X.applicationFilePath() -> str (shared captured text)
applicationName attribute Any (shared captured text)
applicationNameChanged function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QApplication.applicationNameChanged; argument details are not documented.
applicationPid function (self) -> int X.applicationPid() -> int (shared captured text)
applicationState function (self) -> Any (shared captured text)
applicationStateChanged function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QApplication.applicationStateChanged; argument details are not documented.
applicationVersion attribute Any (shared captured text)
applicationVersionChanged function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QApplication.applicationVersionChanged; argument details are not documented.
arguments function (self) -> tuple X.arguments() -> tuple (shared captured text)
autoSipEnabled attribute bool Toggles automatic SIP (software input panel) visibility (shared captured text)
beep function (self) -> None Sounds the bell, using the default volume and sound. (shared captured text)
blockSignals function (self, b: Any) -> bool X.blockSignals(b) -> bool (shared captured text)
changeOverrideCursor function (self, arg__1: Any) -> Any (shared captured text)
childEvent function (self, event: Any) -> Any (shared captured text)
children function (self) -> tuple X.children() -> tuple (shared captured text)
className function (self, *args: Any, **kwargs: Any) -> Any Return the classname of the object (shared captured text)
clipboard function (self) -> Any X.clipboard() -> PythonQt.QtGui.QClipboard (shared captured text)
closeAllWindows function (self) -> None Closes all top-level windows. (shared captured text)
closingDown function (self) -> bool X.closingDown() -> bool (shared captured text)
colorSpec function (self) -> int X.colorSpec() -> int (shared captured text)
commitDataRequest function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QApplication.commitDataRequest; argument details are not documented.
connect function (self, signal: Any, receiver: Any, slot: Any, type: Any) -> bool X.connect(signal, receiver, slot, type) -> bool (shared captured text)
cursorFlashTime attribute int This property holds the text cursor's flash (blink) time in milliseconds (shared captured text)
customEvent function (self, event: Any) -> Any (shared captured text)
delete function (self, *args: Any, **kwargs: Any) -> Any Deletes the C++ object (at your own risk, my friend!) (shared captured text)
deleteLater function (self) -> Any (shared captured text)
desktop function (self) -> Any X.desktop() -> PythonQt.QtGui.QDesktopWidget (shared captured text)
desktopFileName attribute Any (shared captured text)
desktopSettingsAware function (self) -> bool X.desktopSettingsAware() -> bool (shared captured text)
destroyed function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QApplication.destroyed; argument details are not documented.
devicePixelRatio function (self) -> float X.devicePixelRatio() -> float (shared captured text)
disconnect function (self, signal: Any, receiver: Any, slot: Any) -> bool X.disconnect(signal, receiver, slot) -> bool (shared captured text)
doubleClickInterval attribute int This property holds the time limit in milliseconds that distinguishes a double click from two consecutive mouse clicks (shared captured text)
dumpObjectInfo function (self) -> Any (shared captured text)
dumpObjectTree function (self) -> Any (shared captured text)
dynamicPropertyNames function (self) -> Any (shared captured text)
enum_1 attribute type Convert a number or string to an integer, or return 0 if no arguments are given. (shared captured text)
event function (self, arg__1: Any) -> bool X.event(arg__1) -> bool (shared captured text)
eventDispatcher function (self) -> Any (shared captured text)
eventFilter function (self, watched: Any, event: Any) -> bool X.eventFilter(watched, event) -> bool (shared captured text)
exec function (self) -> int X.exec() -> int (shared captured text)
exit function (self, retcode: Any) -> Any (shared captured text)
findChild function (self, type: Any, name: Any) -> Any X.findChild(type, name) -> PythonQt.private.QObject (shared captured text)
findChildren function (self, type: Any, name: Any) -> tuple X.findChildren(type, name) -> tuple (shared captured text)
flush function (self) -> Any (shared captured text)
focusChanged function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QApplication.focusChanged; argument details are not documented.
focusObject function (self) -> Any X.focusObject() -> PythonQt.private.QObject (shared captured text)
focusObjectChanged function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QApplication.focusObjectChanged; argument details are not documented.
focusWidget function (self) -> Any X.focusWidget() -> PythonQt.QtGui.QWidget (shared captured text)
focusWindow function (self) -> Any X.focusWindow() -> PythonQt.QtGui.QWindow (shared captured text)
focusWindowChanged function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QApplication.focusWindowChanged; argument details are not documented.
font function (self, arg__1: Any) -> Any X.font(arg__1) -> PythonQt.QtGui.QFont (shared captured text)
fontChanged function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QApplication.fontChanged; argument details are not documented.
fontDatabaseChanged function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QApplication.fontDatabaseChanged; argument details are not documented.
fontMetrics function (self) -> Any X.fontMetrics() -> PythonQt.QtGui.QFontMetrics (shared captured text)
globalStrut attribute QSize (shared captured text)
hasPendingEvents function (self) -> bool X.hasPendingEvents() -> bool (shared captured text)
help function (self, *args: Any, **kwargs: Any) -> Any Shows the help of available methods for this class (shared captured text)
inherits function (self, *args: Any, **kwargs: Any) -> Any Returns if the class inherits or is of given type name (shared captured text)
inputMethod function (self) -> Any X.inputMethod() -> PythonQt.QtGui.QInputMethod (shared captured text)
installEventFilter function (self, filterObj: Any) -> Any (shared captured text)
installTranslator function (self, messageFile: Any) -> bool X.installTranslator(messageFile) -> bool (shared captured text)
instance function (self) -> Any X.instance() -> PythonQt.QtCore.QCoreApplication (shared captured text)
isEffectEnabled function (self, arg__1: Any) -> bool X.isEffectEnabled(arg__1) -> bool (shared captured text)
isFallbackSessionManagementEnabled function (self) -> bool X.isFallbackSessionManagementEnabled() -> bool (shared captured text)
isLeftToRight function (self) -> bool X.isLeftToRight() -> bool (shared captured text)
isQuitLockEnabled function (self) -> bool X.isQuitLockEnabled() -> bool (shared captured text)
isRightToLeft function (self) -> bool X.isRightToLeft() -> bool (shared captured text)
isSavingSession function (self) -> bool X.isSavingSession() -> bool (shared captured text)
isSessionRestored function (self) -> bool X.isSessionRestored() -> bool (shared captured text)
isSetuidAllowed function (self) -> bool X.isSetuidAllowed() -> bool (shared captured text)
isSignalConnected function (self, signal: Any) -> bool X.isSignalConnected(signal) -> bool (shared captured text)
isWidgetType function (self) -> bool X.isWidgetType() -> bool (shared captured text)
isWindowType function (self) -> bool X.isWindowType() -> bool (shared captured text)
keyboardInputInterval attribute int This property holds the time limit in milliseconds that distinguishes a key press from two consecutive key presses (shared captured text)
keyboardModifiers function (self) -> Any (shared captured text)
killTimer function (self, id: Any) -> Any (shared captured text)
lastWindowClosed function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QApplication.lastWindowClosed; argument details are not documented.
layoutDirection attribute Any (shared captured text)
layoutDirectionChanged function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QApplication.layoutDirectionChanged; argument details are not documented.
libraryPaths function (self) -> tuple X.libraryPaths() -> tuple (shared captured text)
metaObject function (self) -> Any X.metaObject() -> PythonQt.QtCore.QMetaObject (shared captured text)
modalWindow function (self) -> Any X.modalWindow() -> PythonQt.QtGui.QWindow (shared captured text)
mouseButtons function (self) -> Any (shared captured text)
moveToThread function (self, thread: Any) -> Any (shared captured text)
notify function (self, arg__1: Any, arg__2: Any) -> bool X.notify(arg__1, arg__2) -> bool (shared captured text)
objectName attribute Any (shared captured text)
objectNameChanged function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QApplication.objectNameChanged; argument details are not documented.
organizationDomain attribute Any (shared captured text)
organizationDomainChanged function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QApplication.organizationDomainChanged; argument details are not documented.
organizationName attribute Any (shared captured text)
organizationNameChanged function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QApplication.organizationNameChanged; argument details are not documented.
overrideCursor function (self) -> Any X.overrideCursor() -> PythonQt.QtGui.QCursor (shared captured text)
palette function (self, arg__1: Any) -> Any X.palette(arg__1) -> PythonQt.QtGui.QPalette (shared captured text)
paletteChanged function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QApplication.paletteChanged; argument details are not documented.
parent function (self) -> Any X.parent() -> PythonQt.private.QObject (shared captured text)
platformName attribute Any (shared captured text)
postEvent function (self, receiver: Any, event: Any, priority: Any) -> Any X.postEvent(receiver, event, priority) (shared captured text)
primaryScreen attribute QScreen (shared captured text)
primaryScreenChanged function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QApplication.primaryScreenChanged; argument details are not documented.
processEvents function (self, arg0: flags, maxtime: Any) -> Any X.processEvents(flags, maxtime) (shared captured text)
property function (self, name: Any) -> Any X.property(name) -> object (shared captured text)
queryKeyboardModifiers function (self) -> Any (shared captured text)
quit function (self) -> Any (shared captured text)
quitLockEnabled attribute Any (shared captured text)
quitOnLastWindowClosed attribute Any (shared captured text)
removeEventFilter function (self, obj: Any) -> Any (shared captured text)
removeLibraryPath function (self, arg__1: Any) -> Any (shared captured text)
removePostedEvents function (self, receiver: Any, eventType: Any) -> Any X.removePostedEvents(receiver, eventType) (shared captured text)
removeTranslator function (self, messageFile: Any) -> bool X.removeTranslator(messageFile) -> bool (shared captured text)
restoreOverrideCursor function (self) -> Any (shared captured text)
saveStateRequest function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QApplication.saveStateRequest; argument details are not documented.
screenAdded function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QApplication.screenAdded; argument details are not documented.
screenRemoved function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QApplication.screenRemoved; argument details are not documented.
screens function (self) -> tuple X.screens() -> tuple (shared captured text)
sendEvent function (self, receiver: Any, event: Any) -> bool X.sendEvent(receiver, event) -> bool (shared captured text)
sendPostedEvents function (self, receiver: Any, event_type: Any) -> Any X.sendPostedEvents(receiver, event_type) (shared captured text)
sender function (self) -> Any X.sender() -> PythonQt.private.QObject (shared captured text)
senderSignalIndex function (self) -> int X.senderSignalIndex() -> int (shared captured text)
sessionId function (self) -> str X.sessionId() -> str (shared captured text)
sessionKey function (self) -> str X.sessionKey() -> str (shared captured text)
setActiveWindow function (self, act: Any) -> None Sets the active window to the active widget in response to a system event. (shared captured text)
setApplicationDisplayName function (self, name: Any) -> Any (shared captured text)
setApplicationName function (self, application: Any) -> Any (shared captured text)
setApplicationVersion function (self, version: Any) -> Any (shared captured text)
setAttribute function (self, attribute: Any, on: Any) -> Any X.setAttribute(attribute, on) (shared captured text)
setAutoSipEnabled function (self, enabled: bool) -> None (shared captured text)
setColorSpec function (self, arg__1: int) -> None (shared captured text)
setCursorFlashTime function (self, arg__1: int) -> None (shared captured text)
setDesktopSettingsAware function (self, on: Any) -> Any (shared captured text)
setDoubleClickInterval function (self, arg__1: int) -> None (shared captured text)
setEffectEnabled function (self, arg__1: Any, enable: bool) -> None X.setEffectEnabled(arg__1, enable) (shared captured text)
setEventDispatcher function (self, eventDispatcher: Any) -> Any (shared captured text)
setFallbackSessionManagementEnabled function (self, arg__1: Any) -> Any (shared captured text)
setFont function (self, arg__1: Any, className: Any) -> None X.setFont(arg__1, className) (shared captured text)
setGlobalStrut function (self, arg__1: Any) -> None (shared captured text)
setKeyboardInputInterval function (self, arg__1: int) -> None (shared captured text)
setLayoutDirection function (self, direction: Any) -> Any (shared captured text)
setLibraryPaths function (self, arg__1: Any) -> Any (shared captured text)
setObjectName function (self, name: Any) -> Any (shared captured text)
setOrganizationDomain function (self, orgDomain: Any) -> Any (shared captured text)
setOrganizationName function (self, orgName: Any) -> Any (shared captured text)
setOverrideCursor function (self, arg__1: Any) -> Any (shared captured text)
setPalette function (self, arg__1: Any, className: Any) -> None X.setPalette(arg__1, className) (shared captured text)
setParent function (self, parent: Any) -> Any (shared captured text)
setProperty function (self, name: Any, value: Any) -> bool X.setProperty(name, value) -> bool (shared captured text)
setQuitLockEnabled function (self, enabled: Any) -> Any (shared captured text)
setQuitOnLastWindowClosed function (self, quit: Any) -> Any (shared captured text)
setSetuidAllowed function (self, allow: Any) -> Any (shared captured text)
setStartDragDistance function (self, l: int) -> None (shared captured text)
setStartDragTime function (self, ms: int) -> None (shared captured text)
setStyle function (self, arg__1: Any) -> Any Sets the application's GUI style to style. (shared captured text)
setStyleSheet function (self, sheet: str) -> None (shared captured text)
setWheelScrollLines function (self, arg__1: int) -> None (shared captured text)
setWindowIcon function (self, icon: Any) -> None (shared captured text)
signalsBlocked function (self) -> bool X.signalsBlocked() -> bool (shared captured text)
startDragDistance attribute int 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… (shared captured text)
startDragTime attribute int This property holds the time in milliseconds that a mouse button must be held down before a drag and drop operation will begin (shared captured text)
startTimer function (self, interval: Any, timerType: Any) -> int X.startTimer(interval, timerType) -> int (shared captured text)
startingUp function (self) -> bool X.startingUp() -> bool (shared captured text)
style function (self) -> Any X.style() -> PythonQt.QtGui.QStyle (shared captured text)
styleHints function (self) -> Any X.styleHints() -> PythonQt.QtGui.QStyleHints (shared captured text)
styleSheet attribute str This property holds the application style sheet (shared captured text)
sync function (self) -> Any (shared captured text)
testAttribute function (self, attribute: Any) -> bool X.testAttribute(attribute) -> bool (shared captured text)
thread function (self) -> Any (shared captured text)
timerEvent function (self, event: Any) -> Any (shared captured text)
topLevelAt function (self, x: Any, y: Any) -> Any X.topLevelAt(x, y) -> PythonQt.QtGui.QWidget (shared captured text)
topLevelWidgets function (self) -> tuple X.topLevelWidgets() -> tuple (shared captured text)
topLevelWindows function (self) -> tuple X.topLevelWindows() -> tuple (shared captured text)
tr function (self, text: Any, ambig: Any, n: Any) -> str X.tr(text, ambig, n) -> str (shared captured text)
translate function (self, context: Any, key: Any, disambiguation: Any, n: Any) -> str X.translate(context, key, disambiguation, n) -> str (shared captured text)
wheelScrollLines attribute int This property holds the number of lines to scroll a widget, when the mouse wheel is rotated. (shared captured text)
widgetAt function (self, x: Any, y: Any) -> Any X.widgetAt(x, y) -> PythonQt.QtGui.QWidget (shared captured text)
windowIcon attribute QIcon This property holds the default window icon (shared captured text)