Skip to content

PythonQt.QtGui.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.
CustomColor attribute Any
ManyColor attribute Any
NormalColor attribute Any
__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.
aboutToQuit function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.QtGui.QApplication.aboutToQuit; argument details are not documented.
activeModalWidget function (self) -> Any X.activeModalWidget() -> PythonQt.QtGui.QWidget
activePopupWidget function (self) -> Any X.activePopupWidget() -> PythonQt.QtGui.QWidget
activeWindow function (self) -> Any X.activeWindow() -> PythonQt.QtGui.QWidget
addLibraryPath function (self, arg__1: Any) -> Any
alert function (self, widget: Any, duration: int) -> None X.alert(widget, duration)
allWidgets function (self) -> tuple X.allWidgets() -> tuple
allWindows function (self) -> tuple X.allWindows() -> tuple
applicationDirPath function (self) -> str X.applicationDirPath() -> str
applicationDisplayName attribute Any
applicationDisplayNameChanged function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.QtGui.QApplication.applicationDisplayNameChanged; argument details are not documented.
applicationFilePath function (self) -> str X.applicationFilePath() -> str
applicationName attribute Any
applicationNameChanged function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.QtGui.QApplication.applicationNameChanged; argument details are not documented.
applicationPid function (self) -> int X.applicationPid() -> int
applicationState function (self) -> Any (shared captured text)
applicationStateChanged function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.QtGui.QApplication.applicationStateChanged; argument details are not documented.
applicationVersion attribute Any
applicationVersionChanged function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.QtGui.QApplication.applicationVersionChanged; argument details are not documented.
arguments function (self) -> tuple X.arguments() -> tuple
autoSipEnabled attribute bool Toggles automatic SIP (software input panel) visibility
beep function (self) -> None Sounds the bell, using the default volume and sound.
blockSignals function (self, b: Any) -> bool X.blockSignals(b) -> bool (shared captured text)
changeOverrideCursor function (self, arg__1: Any) -> Any
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
closeAllWindows function (self) -> None Closes all top-level windows.
closingDown function (self) -> bool X.closingDown() -> bool
colorSpec function (self) -> int X.colorSpec() -> int
commitDataRequest function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.QtGui.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
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
desktopFileName attribute Any
desktopSettingsAware function (self) -> bool X.desktopSettingsAware() -> bool
destroyed function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.QtGui.QApplication.destroyed; argument details are not documented.
devicePixelRatio function (self) -> float X.devicePixelRatio() -> float
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
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
eventDispatcher function (self) -> Any
eventFilter function (self, watched: Any, event: Any) -> bool X.eventFilter(watched, event) -> bool (shared captured text)
exec function (self) -> int X.exec() -> int
exit function (self, retcode: Any) -> Any
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
focusChanged function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.QtGui.QApplication.focusChanged; argument details are not documented.
focusObject function (self) -> Any X.focusObject() -> PythonQt.private.QObject
focusObjectChanged function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.QtGui.QApplication.focusObjectChanged; argument details are not documented.
focusWidget function (self) -> Any X.focusWidget() -> PythonQt.QtGui.QWidget
focusWindow function (self) -> Any X.focusWindow() -> PythonQt.QtGui.QWindow
focusWindowChanged function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.QtGui.QApplication.focusWindowChanged; argument details are not documented.
font function (self, arg__1: Any) -> Any X.font(arg__1) -> PythonQt.QtGui.QFont
fontChanged function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.QtGui.QApplication.fontChanged; argument details are not documented.
fontDatabaseChanged function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.QtGui.QApplication.fontDatabaseChanged; argument details are not documented.
fontMetrics function (self) -> Any X.fontMetrics() -> PythonQt.QtGui.QFontMetrics
globalStrut attribute QSize
hasPendingEvents function (self) -> bool X.hasPendingEvents() -> bool
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
installEventFilter function (self, filterObj: Any) -> Any (shared captured text)
installTranslator function (self, messageFile: Any) -> bool X.installTranslator(messageFile) -> bool
instance function (self) -> Any X.instance() -> PythonQt.QtCore.QCoreApplication
isEffectEnabled function (self, arg__1: Any) -> bool X.isEffectEnabled(arg__1) -> bool
isFallbackSessionManagementEnabled function (self) -> bool X.isFallbackSessionManagementEnabled() -> bool
isLeftToRight function (self) -> bool X.isLeftToRight() -> bool (shared captured text)
isQuitLockEnabled function (self) -> bool X.isQuitLockEnabled() -> bool
isRightToLeft function (self) -> bool X.isRightToLeft() -> bool (shared captured text)
isSavingSession function (self) -> bool X.isSavingSession() -> bool
isSessionRestored function (self) -> bool X.isSessionRestored() -> bool
isSetuidAllowed function (self) -> bool X.isSetuidAllowed() -> bool
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
keyboardModifiers function (self) -> Any
killTimer function (self, id: Any) -> Any (shared captured text)
lastWindowClosed function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.QtGui.QApplication.lastWindowClosed; argument details are not documented.
layoutDirection attribute Any (shared captured text)
layoutDirectionChanged function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.QtGui.QApplication.layoutDirectionChanged; argument details are not documented.
libraryPaths function (self) -> tuple X.libraryPaths() -> tuple
metaObject function (self) -> Any X.metaObject() -> PythonQt.QtCore.QMetaObject (shared captured text)
modalWindow function (self) -> Any X.modalWindow() -> PythonQt.QtGui.QWindow
mouseButtons function (self) -> Any
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
objectName attribute Any (shared captured text)
objectNameChanged function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.QtGui.QApplication.objectNameChanged; argument details are not documented.
organizationDomain attribute Any
organizationDomainChanged function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.QtGui.QApplication.organizationDomainChanged; argument details are not documented.
organizationName attribute Any
organizationNameChanged function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.QtGui.QApplication.organizationNameChanged; argument details are not documented.
overrideCursor function (self) -> Any X.overrideCursor() -> PythonQt.QtGui.QCursor
palette function (self, arg__1: Any) -> Any X.palette(arg__1) -> PythonQt.QtGui.QPalette
paletteChanged function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.QtGui.QApplication.paletteChanged; argument details are not documented.
parent function (self) -> Any X.parent() -> PythonQt.private.QObject (shared captured text)
platformName attribute Any
postEvent function (self, receiver: Any, event: Any, priority: Any) -> Any X.postEvent(receiver, event, priority)
primaryScreen attribute QScreen
primaryScreenChanged function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.QtGui.QApplication.primaryScreenChanged; argument details are not documented.
processEvents function (self, arg0: flags, maxtime: Any) -> Any X.processEvents(flags, maxtime)
property function (self, name: Any) -> Any X.property(name) -> object (shared captured text)
queryKeyboardModifiers function (self) -> Any
quit function (self) -> Any
quitLockEnabled attribute Any
quitOnLastWindowClosed attribute Any
removeEventFilter function (self, obj: Any) -> Any (shared captured text)
removeLibraryPath function (self, arg__1: Any) -> Any
removePostedEvents function (self, receiver: Any, eventType: Any) -> Any X.removePostedEvents(receiver, eventType)
removeTranslator function (self, messageFile: Any) -> bool X.removeTranslator(messageFile) -> bool
restoreOverrideCursor function (self) -> Any
saveStateRequest function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.QtGui.QApplication.saveStateRequest; argument details are not documented.
screenAdded function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.QtGui.QApplication.screenAdded; argument details are not documented.
screenRemoved function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.QtGui.QApplication.screenRemoved; argument details are not documented.
screens function (self) -> tuple X.screens() -> tuple
sendEvent function (self, receiver: Any, event: Any) -> bool X.sendEvent(receiver, event) -> bool
sendPostedEvents function (self, receiver: Any, event_type: Any) -> Any X.sendPostedEvents(receiver, event_type)
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
sessionKey function (self) -> str X.sessionKey() -> str
setActiveWindow function (self, act: Any) -> None Sets the active window to the active widget in response to a system event.
setApplicationDisplayName function (self, name: Any) -> Any
setApplicationName function (self, application: Any) -> Any
setApplicationVersion function (self, version: Any) -> Any
setAttribute function (self, attribute: Any, on: Any) -> Any X.setAttribute(attribute, on)
setAutoSipEnabled function (self, enabled: bool) -> None
setColorSpec function (self, arg__1: int) -> None
setCursorFlashTime function (self, arg__1: int) -> None
setDesktopSettingsAware function (self, on: Any) -> Any
setDoubleClickInterval function (self, arg__1: int) -> None
setEffectEnabled function (self, arg__1: Any, enable: bool) -> None X.setEffectEnabled(arg__1, enable)
setEventDispatcher function (self, eventDispatcher: Any) -> Any
setFallbackSessionManagementEnabled function (self, arg__1: Any) -> Any
setFont function (self, arg__1: Any, className: Any) -> None X.setFont(arg__1, className)
setGlobalStrut function (self, arg__1: Any) -> None
setKeyboardInputInterval function (self, arg__1: int) -> None
setLayoutDirection function (self, direction: Any) -> Any (shared captured text)
setLibraryPaths function (self, arg__1: Any) -> Any
setObjectName function (self, name: Any) -> Any (shared captured text)
setOrganizationDomain function (self, orgDomain: Any) -> Any
setOrganizationName function (self, orgName: Any) -> Any
setOverrideCursor function (self, arg__1: Any) -> Any
setPalette function (self, arg__1: Any, className: Any) -> None X.setPalette(arg__1, className)
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
setQuitOnLastWindowClosed function (self, quit: Any) -> Any
setSetuidAllowed function (self, allow: Any) -> Any
setStartDragDistance function (self, l: int) -> None
setStartDragTime function (self, ms: int) -> None
setStyle function (self, arg__1: Any) -> Any Sets the application's GUI style to style.
setStyleSheet function (self, sheet: str) -> None
setWheelScrollLines function (self, arg__1: int) -> None
setWindowIcon function (self, icon: Any) -> None
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…
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
startTimer function (self, interval: Any, timerType: Any) -> int X.startTimer(interval, timerType) -> int (shared captured text)
startingUp function (self) -> bool X.startingUp() -> bool
style function (self) -> Any X.style() -> PythonQt.QtGui.QStyle
styleHints function (self) -> Any X.styleHints() -> PythonQt.QtGui.QStyleHints
styleSheet attribute str This property holds the application style sheet
sync function (self) -> Any
testAttribute function (self, attribute: Any) -> bool X.testAttribute(attribute) -> bool
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
topLevelWidgets function (self) -> tuple X.topLevelWidgets() -> tuple
topLevelWindows function (self) -> tuple X.topLevelWindows() -> tuple
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
wheelScrollLines attribute int This property holds the number of lines to scroll a widget, when the mouse wheel is rotated.
widgetAt function (self, x: Any, y: Any) -> Any X.widgetAt(x, y) -> PythonQt.QtGui.QWidget
windowIcon attribute QIcon This property holds the default window icon