Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QApplication Class Reference

The QApplication class manages the GUI application's control flow and main settings. More...

#include <qapplication.h>

+ Inheritance diagram for QApplication:
+ Collaboration diagram for QApplication:

Public Slots

void setStyleSheet (const QString &sheet)
 
void setAutoSipEnabled (const bool enabled)
 
static void closeAllWindows ()
 Closes all top-level windows.
 
static void aboutQt ()
 Displays a simple message box about Qt.
 
- Public Slots inherited from QCoreApplication
static void quit ()
 \threadsafe
 
static void exit (int retcode=0)
 Tells the application to exit with a return code.
 
- Public Slots inherited from QObject
void deleteLater ()
 \threadsafe
 

Signals

void focusChanged (QWidget *old, QWidget *now)
 
- Signals inherited from QGuiApplication
void fontDatabaseChanged ()
 This signal is emitted when the available fonts have changed.
 
void screenAdded (QScreen *screen)
 This signal is emitted whenever a new screen screen has been added to the system.
 
void screenRemoved (QScreen *screen)
 This signal is emitted whenever a screen is removed from the system.
 
void primaryScreenChanged (QScreen *screen)
 
void lastWindowClosed ()
 This signal is emitted from exec() when the last visible \l{Primary and Secondary Windows}{primary window} (i.e.
 
void focusObjectChanged (QObject *focusObject)
 This signal is emitted when final receiver of events tied to focus is changed.
 
void focusWindowChanged (QWindow *focusWindow)
 This signal is emitted when the focused window changes.
 
void applicationStateChanged (Qt::ApplicationState state)
 
void layoutDirectionChanged (Qt::LayoutDirection direction)
 
void commitDataRequest (QSessionManager &sessionManager)
 
void saveStateRequest (QSessionManager &sessionManager)
 
void applicationDisplayNameChanged ()
 
- Signals inherited from QCoreApplication
void aboutToQuit (QPrivateSignal)
 This signal is emitted when the application is about to quit the main event loop, e.g.
 
void organizationNameChanged ()
 
void organizationDomainChanged ()
 
void applicationNameChanged ()
 
void applicationVersionChanged ()
 
- Signals inherited from QObject
void destroyed (QObject *=nullptr)
 This signal is emitted immediately before the object obj is destroyed, after any instances of QPointer have been notified, and cannot be blocked.
 
void objectNameChanged (const QString &objectName, QPrivateSignal)
 This signal is emitted after the object's name has been changed.
 

Public Member Functions

 QApplication (int &argc, char **argv, int=ApplicationFlags)
 Initializes the window system and constructs an application object with argc command line arguments in argv.
 
virtual ~QApplication ()
 Cleans up any window system resources that were allocated by this application.
 
bool notify (QObject *, QEvent *) override
 \reimp
 
QString styleSheet () const
 
bool autoSipEnabled () const
 
- Public Member Functions inherited from QGuiApplication
 QGuiApplication (int &argc, char **argv, int=ApplicationFlags)
 Initializes the window system and constructs an application object with argc command line arguments in argv.
 
 ~QGuiApplication ()
 Destructs the application.
 
Q_SLOT void setBadgeNumber (qint64 number)
 Sets the application's badge to number.
 
qreal devicePixelRatio () const
 Returns the highest screen device pixel ratio found on the system.
 
bool notify (QObject *, QEvent *) override
 \reimp
 
bool isSessionRestored () const
 Returns true if the application has been restored from an earlier \l{Session Management}{session}; otherwise returns false.
 
QString sessionId () const
 Returns the current \l{Session Management}{session's} identifier.
 
QString sessionKey () const
 Returns the session key in the current \l{Session Management}{session}.
 
bool isSavingSession () const
 
- Public Member Functions inherited from QCoreApplication
 QCoreApplication (int &argc, char **argv, int=ApplicationFlags)
 Constructs a Qt core application.
 
 ~QCoreApplication ()
 Destroys the QCoreApplication object.
 
void installNativeEventFilter (QAbstractNativeEventFilter *filterObj)
 Installs an event filter filterObj for all native events received by the application in the main thread.
 
void removeNativeEventFilter (QAbstractNativeEventFilter *filterObj)
 Removes an event filterObject from this object.
 
- Public Member Functions inherited from QObject
Q_INVOKABLE QObject (QObject *parent=nullptr)
 Constructs an object with parent object parent.
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects.
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 Filters events if this object has been installed as an event filter for the watched object.
 
QString objectName () const
 
Q_WEAK_OVERLOAD void setObjectName (const QString &name)
 Sets the object's name to name.
 
void setObjectName (QAnyStringView name)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
QBindable< QStringbindableObjectName ()
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false.
 
bool isWindowType () const
 Returns true if the object is a window; otherwise returns false.
 
bool isQuickItemType () const
 Returns true if the object is a QQuickItem; otherwise returns false.
 
bool signalsBlocked () const noexcept
 Returns true if signals are blocked; otherwise returns false.
 
bool blockSignals (bool b) noexcept
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it).
 
QThreadthread () const
 Returns the thread in which the object lives.
 
bool moveToThread (QThread *thread QT6_DECL_NEW_OVERLOAD_TAIL)
 Changes the thread affinity for this object and its children and returns true on success.
 
int startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer)
 This is an overloaded function that will start a timer of type timerType and a timeout of interval milliseconds.
 
int startTimer (std::chrono::nanoseconds time, Qt::TimerType timerType=Qt::CoarseTimer)
 
void killTimer (int id)
 Kills the timer with timer identifier, id.
 
void killTimer (Qt::TimerId id)
 
template<typename T >
findChild (QAnyStringView aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 Returns the child of this object that can be cast into type T and that is called name, or \nullptr if there is no such object.
 
template<typename T >
QList< T > findChildren (QAnyStringView aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects.
 
template<typename T >
findChild (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
template<typename T >
QList< T > findChildren (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
const QObjectListchildren () const
 Returns a list of child objects.
 
void setParent (QObject *parent)
 Makes the object a child of parent.
 
void installEventFilter (QObject *filterObj)
 Installs an event filter filterObj on this object.
 
void removeEventFilter (QObject *obj)
 Removes an event filter object obj from this object.
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=nullptr, const QObject *receiver=nullptr, const char *member=nullptr) const
 
bool disconnect (const QObject *receiver, const char *member=nullptr) const
 
void dumpObjectTree () const
 Dumps a tree of children to the debug output.
 
void dumpObjectInfo () const
 Dumps information about signal connections, etc.
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value.
 
bool setProperty (const char *name, QVariant &&value)
 
QVariant property (const char *name) const
 Returns the value of the object's name property.
 
QList< QByteArraydynamicPropertyNames () const
 
QBindingStoragebindingStorage ()
 
const QBindingStoragebindingStorage () const
 
QObjectparent () const
 Returns a pointer to the parent object.
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false.
 

Static Public Member Functions

static QStylestyle ()
 Returns the application's style object.
 
static void setStyle (QStyle *)
 Sets the application's GUI style to style.
 
static QStylesetStyle (const QString &)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Requests a QStyle object for style from the QStyleFactory.
 
static QPalette palette (const QWidget *)
 If a widget is passed, the default palette for the widget's class is returned.
 
static QPalette palette (const char *className)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns the palette for widgets of the given className.
 
static void setPalette (const QPalette &, const char *className=nullptr)
 Changes the application palette to palette.
 
static QFont font ()
 Returns the default application font.
 
static QFont font (const QWidget *)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns the default font for the widget.
 
static QFont font (const char *className)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns the font for widgets of the given className.
 
static void setFont (const QFont &, const char *className=nullptr)
 Changes the default application font to font.
 
static QWidgetList allWidgets ()
 Returns a list of all the widgets in the application.
 
static QWidgetList topLevelWidgets ()
 Returns a list of the top-level widgets (windows) in the application.
 
static QWidgetactivePopupWidget ()
 Returns the active popup widget.
 
static QWidgetactiveModalWidget ()
 Returns the active modal widget.
 
static QWidgetfocusWidget ()
 Returns the application widget that has the keyboard input focus, or \nullptr if no widget in this application has the focus.
 
static QWidgetactiveWindow ()
 Returns the application top-level window that has the keyboard input focus, or \nullptr if no application window has the focus.
 
static QWidgetwidgetAt (const QPoint &p)
 Returns the widget at global screen position point, or \nullptr if there is no Qt widget there.
 
static QWidgetwidgetAt (int x, int y)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns the widget at global screen position (x, y), or \nullptr if there is no Qt widget there.
 
static QWidgettopLevelAt (const QPoint &p)
 Returns the top-level widget at the given point; returns \nullptr if there is no such widget.
 
static QWidgettopLevelAt (int x, int y)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns the top-level widget at the point ({x}, {y}); returns 0 if there is no such widget.
 
static void beep ()
 Sounds the bell, using the default volume and sound.
 
static void alert (QWidget *widget, int duration=0)
 
static void setCursorFlashTime (int)
 
static int cursorFlashTime ()
 
static void setDoubleClickInterval (int)
 
static int doubleClickInterval ()
 
static void setKeyboardInputInterval (int)
 
static int keyboardInputInterval ()
 
static void setStartDragTime (int ms)
 
static int startDragTime ()
 
static void setStartDragDistance (int l)
 
static int startDragDistance ()
 
static bool isEffectEnabled (Qt::UIEffect)
 Returns true if effect is enabled; otherwise returns false.
 
static void setEffectEnabled (Qt::UIEffect, bool enable=true)
 Enables the UI effect effect if enable is true, otherwise the effect will not be used.
 
static int exec ()
 Enters the main event loop and waits until exit() is called, then returns the value that was set to exit() (which is 0 if exit() is called via quit()).
 
static QPalette palette ()
 Returns the current application palette.
 
- Static Public Member Functions inherited from QGuiApplication
static void setApplicationDisplayName (const QString &name)
 
static QString applicationDisplayName ()
 
static void setDesktopFileName (const QString &name)
 
static QString desktopFileName ()
 
static QWindowList allWindows ()
 Returns a list of all the windows in the application.
 
static QWindowList topLevelWindows ()
 Returns a list of the top-level windows in the application.
 
static QWindowtopLevelAt (const QPoint &pos)
 Returns the top level window at the given position pos, if any.
 
static void setWindowIcon (const QIcon &icon)
 
static QIcon windowIcon ()
 
static QString platformName ()
 
static QWindowmodalWindow ()
 Returns the most recently shown modal window.
 
static QWindowfocusWindow ()
 Returns the QWindow that receives events tied to focus, such as key events.
 
static QObjectfocusObject ()
 Returns the QObject in currently active window that will be final receiver of events tied to focus, such as key events.
 
static QScreenprimaryScreen ()
 
static QList< QScreen * > screens ()
 Returns a list of all the screens associated with the windowing system the application is connected to.
 
static QScreenscreenAt (const QPoint &point)
 Returns the screen at point, or \nullptr if outside of any screen.
 
static QCursoroverrideCursor ()
 Returns the active application override cursor.
 
static void setOverrideCursor (const QCursor &)
 Sets the application override cursor to cursor.
 
static void changeOverrideCursor (const QCursor &)
 Changes the currently active application override cursor to cursor.
 
static void restoreOverrideCursor ()
 Undoes the last setOverrideCursor().
 
static QFont font ()
 Returns the default application font.
 
static void setFont (const QFont &)
 Changes the default application font to font.
 
static QClipboardclipboard ()
 Returns the object for interacting with the clipboard.
 
static QPalette palette ()
 Returns the current application palette.
 
static void setPalette (const QPalette &pal)
 Changes the application palette to pal.
 
static Qt::KeyboardModifiers keyboardModifiers ()
 Returns the current state of the modifier keys on the keyboard.
 
static Qt::KeyboardModifiers queryKeyboardModifiers ()
 Queries and returns the state of the modifier keys on the keyboard.
 
static Qt::MouseButtons mouseButtons ()
 Returns the current state of the buttons on the mouse.
 
static void setLayoutDirection (Qt::LayoutDirection direction)
 
static Qt::LayoutDirection layoutDirection ()
 
static bool isRightToLeft ()
 Returns true if the application's layout direction is Qt::RightToLeft; otherwise returns false.
 
static bool isLeftToRight ()
 Returns true if the application's layout direction is Qt::LeftToRight; otherwise returns false.
 
static QStyleHintsstyleHints ()
 Returns the application's style hints.
 
static void setDesktopSettingsAware (bool on)
 Sets whether Qt should use the system's standard colors, fonts, etc., to on.
 
static bool desktopSettingsAware ()
 Returns true if Qt is set to use the system's standard colors, fonts, etc.; otherwise returns false.
 
static QInputMethodinputMethod ()
 returns the input method.
 
static QPlatformNativeInterfaceplatformNativeInterface ()
 
static QFunctionPointer platformFunction (const QByteArray &function)
 
static void setQuitOnLastWindowClosed (bool quit)
 
static bool quitOnLastWindowClosed ()
 
static Qt::ApplicationState applicationState ()
 
static void setHighDpiScaleFactorRoundingPolicy (Qt::HighDpiScaleFactorRoundingPolicy policy)
 
static Qt::HighDpiScaleFactorRoundingPolicy highDpiScaleFactorRoundingPolicy ()
 
static int exec ()
 Enters the main event loop and waits until exit() is called, and then returns the value that was set to exit() (which is 0 if exit() is called via quit()).
 
static void sync ()
 
- Static Public Member Functions inherited from QCoreApplication
static QStringList arguments ()
 
static void setAttribute (Qt::ApplicationAttribute attribute, bool on=true)
 Sets the attribute attribute if on is true; otherwise clears the attribute.
 
static bool testAttribute (Qt::ApplicationAttribute attribute)
 Returns true if attribute attribute is set; otherwise returns false.
 
static void setOrganizationDomain (const QString &orgDomain)
 
static QString organizationDomain ()
 
static void setOrganizationName (const QString &orgName)
 [11]
 
static QString organizationName ()
 
static void setApplicationName (const QString &application)
 
static QString applicationName ()
 
static void setApplicationVersion (const QString &version)
 
static QString applicationVersion ()
 
static void setSetuidAllowed (bool allow)
 
static bool isSetuidAllowed ()
 
static QCoreApplicationinstance () noexcept
 Returns a pointer to the application's QCoreApplication (or QGuiApplication/QApplication) instance.
 
static int exec ()
 Enters the main event loop and waits until exit() is called.
 
static void processEvents (QEventLoop::ProcessEventsFlags flags=QEventLoop::AllEvents)
 Processes some pending events for the calling thread according to the specified flags.
 
static void processEvents (QEventLoop::ProcessEventsFlags flags, int maxtime)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Processes pending events for the calling thread for ms milliseconds or until there are no more events to process, whichever is shorter.
 
static void processEvents (QEventLoop::ProcessEventsFlags flags, QDeadlineTimer deadline)
 
static bool sendEvent (QObject *receiver, QEvent *event)
 Sends event event directly to receiver receiver, using the notify() function.
 
static void postEvent (QObject *receiver, QEvent *event, int priority=Qt::NormalEventPriority)
 
static void sendPostedEvents (QObject *receiver=nullptr, int event_type=0)
 Immediately dispatches all events which have been previously queued with QCoreApplication::postEvent() and which are for the object receiver and have the event type event_type.
 
static void removePostedEvents (QObject *receiver, int eventType=0)
 
static QAbstractEventDispatchereventDispatcher ()
 Returns a pointer to the event dispatcher object for the main thread.
 
static void setEventDispatcher (QAbstractEventDispatcher *eventDispatcher)
 Sets the event dispatcher for the main thread to eventDispatcher.
 
static bool startingUp ()
 Returns true if an application object has not been created yet; otherwise returns false.
 
static bool closingDown ()
 Returns true if the application objects are being destroyed; otherwise returns false.
 
static QString applicationDirPath ()
 Returns the directory that contains the application executable.
 
static QString applicationFilePath ()
 Returns the file path of the application executable.
 
static qint64 applicationPid () Q_DECL_CONST_FUNCTION
 
static bool installTranslator (QTranslator *messageFile)
 Adds the translation file translationFile to the list of translation files to be used for translations.
 
static bool removeTranslator (QTranslator *messageFile)
 Removes the translation file translationFile from the list of translation files used by this application.
 
static QString translate (const char *context, const char *key, const char *disambiguation=nullptr, int n=-1)
 \threadsafe
 
static bool isQuitLockEnabled ()
 
static void setQuitLockEnabled (bool enabled)
 
- Static Public Member Functions inherited from QObject
static QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 \threadsafe
 
static QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
template<typename Func1 , typename Func2 >
static QMetaObject::Connection connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::ContextTypeForFunctor< Func2 >::ContextType *context, Func2 &&slot, Qt::ConnectionType type=Qt::AutoConnection)
 
template<typename Func1 , typename Func2 >
static QMetaObject::Connection connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, Func2 &&slot)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 \threadsafe
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static bool disconnect (const QMetaObject::Connection &)
 Disconnect a connection.
 
template<typename Func1 , typename Func2 >
static bool disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiver, Func2 slot)
 
template<typename Func1 >
static bool disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *receiver, void **zero)
 

Protected Member Functions

bool event (QEvent *) override
 \reimp
 
bool compressEvent (QEvent *, QObject *receiver, QPostEventList *) override
 
- Protected Member Functions inherited from QGuiApplication
bool event (QEvent *) override
 \reimp
 
bool compressEvent (QEvent *, QObject *receiver, QPostEventList *) override
 
 QGuiApplication (QGuiApplicationPrivate &p)
 
- Protected Member Functions inherited from QCoreApplication
 QCoreApplication (QCoreApplicationPrivate &p)
 
- Protected Member Functions inherited from QObject
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns \nullptr.
 
int senderSignalIndex () const
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal.
 
bool isSignalConnected (const QMetaMethod &signal) const
 
virtual void timerEvent (QTimerEvent *event)
 This event handler can be reimplemented in a subclass to receive timer events for the object.
 
virtual void childEvent (QChildEvent *event)
 This event handler can be reimplemented in a subclass to receive child events.
 
virtual void customEvent (QEvent *event)
 This event handler can be reimplemented in a subclass to receive custom events.
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 
 QObject (QObjectPrivate &dd, QObject *parent=nullptr)
 

Properties

int cursorFlashTime
 the text cursor's flash (blink) time in milliseconds
 
int doubleClickInterval
 the time limit in milliseconds that distinguishes a double click from two consecutive mouse clicks
 
int keyboardInputInterval
 the time limit in milliseconds that distinguishes a key press from two consecutive key presses
 
int startDragTime
 the time in milliseconds that a mouse button must be held down before a drag and drop operation will begin
 
int startDragDistance
 the minimum distance required for a drag and drop operation to start.
 
QString styleSheet
 the application style sheet
 
bool autoSipEnabled
 toggles automatic SIP (software input panel) visibility
 
- Properties inherited from QGuiApplication
QIcon windowIcon
 the default window icon
 
QString applicationDisplayName
 the user-visible name of this application
 
QString desktopFileName
 the base name of the desktop entry for this application
 
Qt::LayoutDirection layoutDirection
 the default layout direction for this application
 
QString platformName
 The name of the underlying platform plugin.
 
bool quitOnLastWindowClosed
 whether the application implicitly quits when the last window is closed.
 
QScreenprimaryScreen
 the primary (or default) screen of the application.
 
- Properties inherited from QCoreApplication
QString applicationName
 the name of this application
 
QString applicationVersion
 the version of this application
 
QString organizationName
 the name of the organization that wrote this application
 
QString organizationDomain
 the Internet domain of the organization that wrote this application
 
bool quitLockEnabled
 Whether the use of the QEventLoopLocker feature can cause the application to quit.
 
- Properties inherited from QObject
QString objectName
 the name of this object
 

Friends

class QGraphicsWidget
 
class QGraphicsItem
 
class QGraphicsScene
 
class QGraphicsScenePrivate
 
class QWidget
 
class QWidgetPrivate
 
class QWidgetWindow
 
class QTranslator
 
class QWidgetAnimator
 
class QShortcut
 
class QLineEdit
 
class QWidgetTextControl
 
class QAction
 
class QGestureManager
 

Related Symbols

(Note that these are not member symbols.)

bool qt_sendSpontaneousEvent (QObject *receiver, QEvent *event)
 \macro qApp
 

Additional Inherited Members

- Public Types inherited from QCoreApplication
enum  { ApplicationFlags = QT_VERSION }
 
- Protected Attributes inherited from QObject
QScopedPointer< QObjectDatad_ptr
 

Detailed Description

The QApplication class manages the GUI application's control flow and main settings.

\inmodule QtWidgets

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 \l 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: \list

  • 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 \l{QApplication::QApplication()} {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 clipboard().

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.

\table \header

  • {2,1} Groups of functions

\row

\row

\row

\row

\row

\row

\row

See also
QCoreApplication, QAbstractEventDispatcher, QEventLoop, QSettings

Definition at line 31 of file qapplication.h.

Constructor & Destructor Documentation

◆ QApplication()

QApplication::QApplication ( int & argc,
char ** argv,
int = ApplicationFlags )

Initializes the window system and constructs an application object with argc command line arguments in argv.

Warning
The data referred to by argc and argv must stay valid for the entire lifetime of the QApplication object. In addition, argc must be greater than zero and argv must contain at least one valid character string.

The global qApp pointer refers to this application object. Only one application object should be created.

This application object must be constructed before any \l{QPaintDevice} {paint devices} (including widgets, pixmaps, bitmaps etc.).

Note
argc and argv might be changed as Qt removes command line arguments that it recognizes.

All Qt programs automatically support the following command line options: \list

  • -style= style, sets the application GUI style. Possible values depend on your system configuration. If you compiled Qt with additional styles or have additional styles as plugins these will be available to the -style command line option. You can also set the style for all Qt applications by setting the QT_STYLE_OVERRIDE environment variable.
  • -style style, is the same as listed above.
  • -stylesheet= stylesheet, sets the application \l styleSheet. The value must be a path to a file that contains the Style Sheet.
    Note
    Relative URLs in the Style Sheet file are relative to the Style Sheet file's path.
  • -stylesheet stylesheet, is the same as listed above.
  • -widgetcount, prints debug message at the end about number of widgets left undestroyed and maximum number of widgets existed at the same time
  • -reverse, sets the application's layout direction to Qt::RightToLeft
  • -qmljsdebugger=, activates the QML/JS debugger with a specified port. The value must be of format port:1234[,block], where block is optional and will make the application wait until a debugger connects to it. \endlist
See also
QCoreApplication::arguments()

Definition at line 455 of file qapplication.cpp.

References d.

◆ ~QApplication()

Member Function Documentation

◆ aboutQt

void QApplication::aboutQt ( )
staticslot

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 \uicontrol Help menu of an application, as shown in the \l{mainwindows/menus}{Menus} example.

This function is a convenience slot for QMessageBox::aboutQt().

Definition at line 1641 of file qapplication.cpp.

References QMessageBox::aboutQt(), and activeWindow().

+ Here is the call graph for this function:

◆ activeModalWidget()

QWidget * QApplication::activeModalWidget ( )
static

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
activePopupWidget(), topLevelWidgets()

Definition at line 649 of file qapplication.cpp.

References QGuiApplication::modalWindow().

Referenced by QApplicationPrivate::dispatchEnterLeave(), QWidget::event(), QApplicationPrivate::tryModalHelper(), and QGraphicsView::viewportEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ activePopupWidget()

QWidget * QApplication::activePopupWidget ( )
static

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
activeModalWidget(), topLevelWidgets()

Definition at line 628 of file qapplication.cpp.

References QApplicationPrivate::popupWidgets.

Referenced by QMenuPrivate::activateAction(), QApplicationPrivate::closeAllPopups(), QApplicationPrivate::dispatchEnterLeave(), QToolBar::event(), QWidgetResizeHandler::eventFilter(), QLineEdit::focusOutEvent(), QWidgetWindow::handleContextMenuEvent(), QWidgetWindow::handleEnterLeaveEvent(), QWidgetWindow::handleGestureEvent(), QWidgetWindow::handleKeyEvent(), QWidgetWindow::handleMouseEvent(), QWidget::mousePressEvent(), notify(), QApplicationPrivate::notify_helper(), qWidgetShortcutContextMatcher(), QApplicationPrivate::sendMouseEvent(), QMenuBarPrivate::setKeyboardMode(), QWidgetPrivate::show_helper(), QApplicationPrivate::tryModalHelper(), QGraphicsView::viewportEvent(), and QApplicationPrivate::windowNeverBlocked().

+ Here is the caller graph for this function:

◆ activeWindow()

QWidget * QApplication::activeWindow ( )
static

Returns the application top-level window that has the keyboard input focus, or \nullptr 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.

See also
QWidget::setFocus(), QWidget::hasFocus(), focusWidget()

Definition at line 1562 of file qapplication.cpp.

Referenced by aboutQt(), QWidgetPrivate::deactivateWidgetCleanup(), QWidget::isActiveWindow(), QPrintDialogPrivate::openWindowsPrintDialogModally(), qWidgetShortcutContextMatcher(), QQC2::QWindowsStyle::styleHint(), and QGraphicsView::viewportEvent().

+ Here is the caller graph for this function:

◆ alert()

void QApplication::alert ( QWidget * widget,
int msec = 0 )
static
Since
4.3

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.

Definition at line 3487 of file qapplication.cpp.

References alert(), QWidget::isActiveWindow, topLevelWidgets(), widget, window(), QWidget::window(), QApplicationPrivate::windowForWidget(), Qt::WindowMinimized, and QWidget::windowState().

Referenced by alert().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ allWidgets()

QWidgetList QApplication::allWidgets ( )
static

Returns a list of all the widgets in the application.

The list is empty (QList::isEmpty()) if there are no widgets.

Note
Some of the widgets may be hidden.

Example:

{
const QWidgetList allWidgets = QApplication::allWidgets();
for (QWidget *widget : allWidgets)
widget->update();
}
See also
topLevelWidgets(), QWidget::isVisible()

Definition at line 1478 of file qapplication.cpp.

References QWidgetPrivate::allWidgets.

Referenced by QApplicationPrivate::handlePaletteChanged(), QWidgetPrivate::isFocusChainConsistent(), setFont(), setStyle(), and updateAllWidgets().

+ Here is the caller graph for this function:

◆ autoSipEnabled()

bool QApplication::autoSipEnabled ( ) const

Definition at line 866 of file qapplication.cpp.

References QApplicationPrivate::autoSipEnabled.

◆ beep()

void QApplication::beep ( )
static

Sounds the bell, using the default volume and sound.

The function is not available in Qt for Embedded Linux.

Definition at line 3668 of file qapplication.cpp.

References QGuiApplicationPrivate::platformIntegration().

Referenced by QMenu::keyPressEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ closeAllWindows

void QApplication::closeAllWindows ( )
staticslot

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 \l quitOnLastWindowClosed is set to false. To trigger application termination from e.g. a menu, use QCoreApplication::quit() instead of this function.

See also
quitOnLastWindowClosed, lastWindowClosed(), QWidget::close(), QWidget::closeEvent(), lastWindowClosed(), QCoreApplication::quit(), topLevelWidgets(), QWidget::isWindow()

Definition at line 1626 of file qapplication.cpp.

Referenced by event().

+ Here is the caller graph for this function:

◆ compressEvent()

bool QApplication::compressEvent ( QEvent * event,
QObject * receiver,
QPostEventList * postedEvents )
overrideprotectedvirtual

Reimplemented from QCoreApplication.

Definition at line 783 of file qapplication.cpp.

References QGuiApplication::compressEvent(), QObject::event(), QEvent::LanguageChange, QEvent::LayoutRequest, QEvent::Move, QMoveEvent::pos(), QUpdateLaterEvent::region(), QEvent::Resize, QResizeEvent::size(), QEvent::UpdateLater, and QEvent::UpdateRequest.

+ Here is the call graph for this function:

◆ cursorFlashTime()

static int QApplication::cursorFlashTime ( )
static

◆ doubleClickInterval()

static int QApplication::doubleClickInterval ( )
static

◆ event()

bool QApplication::event ( QEvent * e)
overrideprotectedvirtual

\reimp

Reimplemented from QObject.

Definition at line 1666 of file qapplication.cpp.

References QEvent::ApplicationFontChange, QEvent::ApplicationPaletteChange, closeAllWindows(), d, Qt::Desktop, Qt::Dialog, QEvent::EnterWhatsThisMode, QWhatsThis::enterWhatsThisMode(), QCoreApplication::event(), QGuiApplication::event(), QEvent::ignore(), QEvent::isAccepted(), QEvent::LanguageChange, list, QEvent::LocaleChange, Qt::Popup, QCoreApplication::postEvent(), Q_ASSERT, QEvent::Quit, QCoreApplication::sendEvent(), QStyle::SH_ToolTip_FallAsleepDelay, QStyle::styleHint(), QWidget::testAttribute(), QEvent::Timer, QEvent::ToolTip, topLevelWidgets(), QEvent::type(), Qt::WA_AlwaysShowToolTips, Qt::WA_DontShowOnScreen, Qt::WA_SetLocale, and QWidget::window().

Referenced by MyApplication::event().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ exec()

int QApplication::exec ( )
static

Enters the main event loop and waits until exit() is called, then returns the value that was set to exit() (which is 0 if exit() is called via quit()).

It is necessary to call this function to start event handling. The main event loop receives events from the window system and dispatches these to the application widgets.

Generally, no user interaction can take place before calling exec(). As a special case, modal widgets like QMessageBox can be used before calling exec(), because modal widgets call exec() to start a local event loop.

To make your application perform idle processing, i.e., executing a special function whenever there are no pending events, use a QChronoTimer with 0ns timeout. More advanced idle processing schemes can be achieved using processEvents().

We recommend that you connect clean-up code to the \l{QCoreApplication::}{aboutToQuit()} signal, instead of putting it in your application's {main()} function. This is because, on some platforms the QApplication::exec() call may not return. For example, on the Windows platform, when the user logs off, the system terminates the process after Qt closes all top-level windows. Hence, there is {no guarantee} that the application will have time to exit its event loop and execute code at the end of the {main()} function, after the QApplication::exec() call.

See also
quitOnLastWindowClosed, QCoreApplication::quit(), QCoreApplication::exit(), QCoreApplication::processEvents(), QCoreApplication::exec()

Definition at line 2560 of file qapplication.cpp.

References QGuiApplication::exec().

Referenced by main(), src_gui_vulkan_qvulkaninstance::main(), src_gui_vulkan_qvulkaninstance2::main(), main(), src_gui_kernel_qguiapplication::main(), src_gui_vulkan_qvulkanwindow::main(), main(), main(), and main_textblock_formats().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ focusChanged

void QApplication::focusChanged ( QWidget * old,
QWidget * now )
signal
Since
4.1

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 \nullptr.

The signal is emitted after both widget have been notified about the change through QFocusEvent.

See also
QWidget::setFocus(), QWidget::clearFocus(), Qt::FocusReason

◆ focusWidget()

◆ font() [1/3]

QFont QApplication::font ( )
static

Returns the default application font.

See also
fontMetrics(), QWidget::font()

Definition at line 1268 of file qapplication.cpp.

References QGuiApplication::font().

Referenced by QWhatsThat::QWhatsThat(), QGraphicsWidget::event(), QWidget::event(), QToolTip::font(), font(), font(), QDockWidgetPrivate::init(), QGraphicsWidgetPrivate::initStyleOptionTitleBar(), QWidgetPrivate::naturalWidgetFont(), QDockWidget::paintEvent(), QGraphicsWidget::paintWindowFrame(), QMdi::SimpleCascader::rearrange(), QGraphicsScenePrivate::resolveFont(), setFont(), QGraphicsScene::setFont(), QAndroidStyle::sizeFromContents(), QWindowsVistaStyle::unpolish(), and QMessageBoxPrivate::updateSize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ font() [2/3]

QFont QApplication::font ( const char * className)
static

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns the font for widgets of the given className.

See also
setFont(), QWidget::font()

Definition at line 1319 of file qapplication.cpp.

References className, font(), hash, and it.

+ Here is the call graph for this function:

◆ font() [3/3]

QFont QApplication::font ( const QWidget * widget)
static

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.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
fontMetrics(), setFont(), QWidget::setFont()

Definition at line 1283 of file qapplication.cpp.

References QHash< QByteArray, QFont >::const_iterator, font(), hash, it, QByteArrayLiteral, QWidget::testAttribute(), Qt::WA_MacMiniSize, Qt::WA_MacSmallSize, and widget.

+ Here is the call graph for this function:

◆ isEffectEnabled()

bool QApplication::isEffectEnabled ( Qt::UIEffect effect)
static

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(), Qt::UIEffect

Definition at line 3654 of file qapplication.cpp.

References CHECK_QAPP_INSTANCE, effect, QApplicationPrivate::enabledAnimations, QPlatformTheme::GeneralUiEffect, QColormap::instance(), and uiEffectToFlag().

Referenced by QMenuPrivate::popup(), QComboBox::showPopup(), and QToolTip::showText().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ keyboardInputInterval()

static int QApplication::keyboardInputInterval ( )
static

◆ notify()

bool QApplication::notify ( QObject * receiver,
QEvent * e )
overridevirtual

\reimp

Reimplemented from QCoreApplication.

Definition at line 2567 of file qapplication.cpp.

References QEvent::ActivationChange, activePopupWidget(), QEvent::ApplicationDeactivate, QGuiApplicationPrivate::captureGlobalModifierState(), QCoreApplicationPrivate::checkReceiverThread(), QEvent::ChildAdded, QEvent::ChildPolished, QEvent::ChildRemoved, QEvent::CloseSoftwareInputPanel, context, QEvent::ContextMenu, QKeyEvent::count(), QThread::currentThread(), d, QEvent::DeferredDelete, QTest::QTouchEventSequence::device, QEvent::DragEnter, QEvent::DragLeave, QEvent::DragMove, QEvent::DragResponse, QEvent::Drop, QEvent::DynamicPropertyChange, QMap< Key, T >::end(), QEvent::Enter, QMap< Key, T >::find(), QEvent::FocusIn, QEvent::FocusOut, QMutableSinglePointEvent::from(), QMutableTouchEvent::from(), QEvent::Gesture, QWidgetPrivate::gestureContext, QEvent::GestureOverride, QGestureManager::gesturePending(), QGestureEvent::gestures(), Qt::GestureStarted, QGesture::gestureType, QApplicationPrivate::GrabAllPoints, QEvent::GraphicsSceneDragEnter, QEvent::GraphicsSceneDragLeave, QEvent::GraphicsSceneDragMove, QEvent::GraphicsSceneDrop, help, QEvent::HoverMove, i, QEvent::IconDrag, QEvent::ignore(), QGuiApplication::inputMethod(), QCoreApplicationPrivate::is_app_closing, QEvent::isAccepted(), QKeyEvent::isAutoRepeat(), QObject::isWidgetType(), QObject::isWindowType(), QKeyEvent::key(), Qt::Key_Backtab, Qt::Key_Down, Qt::Key_Left, Qt::Key_Right, Qt::Key_Tab, Qt::Key_Up, QEvent::KeyPress, QEvent::KeyRelease, QEvent::Leave, QEvent::LocaleChange, QWidget::mapToParent(), QEvent::MetaCall, QKeyEvent::modifiers(), QEvent::MouseButtonDblClick, QEvent::MouseButtonPress, QEvent::MouseButtonRelease, QEvent::MouseMove, QEvent::NativeGesture, QEvent::NetworkReplyUpdated, Qt::NoScrollPhase, QEvent::OrientationChange, QEvent::Paint, QGuiApplication::platformNativeInterface(), QTest::QTouchEventSequence::point(), QTest::QTouchEventSequence::points, Q_ASSERT, Q_FALLTHROUGH, Q_UNLIKELY, qobject_cast< QWidget * >(), qt_in_tab_key_event, qt_sendShortcutOverrideEvent(), QEvent::QueryWhatsThis, qWarning, Qt::ReceivePartialGestures, QEvent::RequestSoftwareInputPanel, Qt::ScrollBegin, Qt::ScrollEnd, Qt::ScrollMomentum, Qt::ScrollUpdate, QDragManager::self(), QGuiApplicationPrivate::sendQWindowEventToQPlatformWindow(), QPointerEvent::setTimestamp(), QStyle::SH_ToolTip_WakeUpDelay, QEvent::ShortcutOverride, QEvent::spontaneous(), QEvent::StatusTip, QEvent::Style, QEvent::StyleChange, QStyle::styleHint(), QEvent::TabletMove, QEvent::TabletPress, QEvent::TabletRelease, QKeyEvent::text(), QInputEvent::timestamp(), QEvent::ToolTip, QEvent::TouchBegin, QEvent::TouchEnd, QInputDevice::TouchPad, QEvent::TouchUpdate, QEvent::type(), QInputDevice::type, QEvent::UpdateLater, QEvent::UpdateRequest, void, Qt::WA_AcceptTouchEvents, Qt::WA_Hover, Qt::WA_NoMousePropagation, Qt::WA_NoMouseReplay, Qt::WA_WState_AcceptedTouchBeginEvent, QEvent::WhatsThis, QEvent::WhatsThisClicked, and QEvent::Wheel.

+ Here is the call graph for this function:

◆ palette() [1/3]

QPalette QGuiApplication::palette ( )
static

Returns the current application palette.

Roles that have not been explicitly set will reflect the system's platform theme.

See also
setPalette()

Definition at line 100 of file qguiapplication.cpp.

Referenced by QMacStyle::drawControl(), QWidget::event(), QWidgetPrivate::naturalWidgetPalette(), palette(), QWindowsVistaStyle::polish(), QWidgetTextControlPrivate::setContent(), setPalette(), QWizardPrivate::updatePalette(), and write_datastream_snippets().

+ Here is the caller graph for this function:

◆ palette() [2/3]

QPalette QApplication::palette ( const char * className)
static

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns the palette for widgets of the given className.

See also
setPalette(), QWidget::palette()

Definition at line 1147 of file qapplication.cpp.

References className, QSet< T >::constEnd(), QSet< T >::constFind(), it, QGuiApplication::palette(), and QApplicationPrivate::widgetPalettes.

+ Here is the call graph for this function:

◆ palette() [3/3]

QPalette QApplication::palette ( const QWidget * widget)
static

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
setPalette(), QWidget::palette()

Definition at line 1124 of file qapplication.cpp.

References QSet< T >::constBegin(), QSet< T >::constFind(), it, palette(), and QApplicationPrivate::widgetPalettes.

+ Here is the call graph for this function:

◆ setAutoSipEnabled

void QApplication::setAutoSipEnabled ( const bool enabled)
slot

Definition at line 861 of file qapplication.cpp.

References QApplicationPrivate::autoSipEnabled, and enabled.

◆ setCursorFlashTime()

void QApplication::setCursorFlashTime ( int msecs)
static

Definition at line 3519 of file qapplication.cpp.

References QGuiApplication::styleHints().

+ Here is the call graph for this function:

◆ setDoubleClickInterval()

void QApplication::setDoubleClickInterval ( int ms)
static

Definition at line 3537 of file qapplication.cpp.

References QGuiApplication::styleHints().

+ Here is the call graph for this function:

◆ setEffectEnabled()

void QApplication::setEffectEnabled ( Qt::UIEffect effect,
bool enable = true )
static

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(), Qt::UIEffect, setDesktopSettingsAware()

Definition at line 3627 of file qapplication.cpp.

References QPlatformTheme::AnimateMenuUiEffect, QPlatformTheme::AnimateTooltipUiEffect, effect, QApplicationPrivate::enabledAnimations, QPlatformTheme::FadeMenuUiEffect, QPlatformTheme::FadeTooltipUiEffect, and uiEffectToFlag().

+ Here is the call graph for this function:

◆ setFont()

void QApplication::setFont ( const QFont & font,
const char * className = nullptr )
static

Changes the default application font to font.

If className is passed, the change applies only to classes that inherit className (as reported by QObject::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 \l{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
font(), fontMetrics(), QWidget::setFont()

Definition at line 1350 of file qapplication.cpp.

References allWidgets(), QEvent::ApplicationFontChange, className, QSet< T >::constBegin(), QSet< T >::constEnd(), font(), hash, QCoreApplicationPrivate::is_app_closing, QCoreApplicationPrivate::is_app_running, it, qApp, QCoreApplication::sendEvent(), QApplicationPrivate::set_font, QGuiApplication::setFont(), and QApplicationPrivate::sys_font.

Referenced by QAndroidStyle::QAndroidStyle(), QToolTip::setFont(), and QApplicationPrivate::setSystemFont().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setKeyboardInputInterval()

void QApplication::setKeyboardInputInterval ( int ms)
static

Definition at line 3556 of file qapplication.cpp.

References QGuiApplication::styleHints().

+ Here is the call graph for this function:

◆ setPalette()

void QApplication::setPalette ( const QPalette & palette,
const char * className = nullptr )
static

Changes the application palette to palette.

If className is passed, the change applies only to widgets that inherit className (as reported by QObject::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 QStyle::polish().

Warning
Do not use this function in conjunction with \l{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
QWidget::setPalette(), palette(), QStyle::polish()

Definition at line 1181 of file qapplication.cpp.

References QApplicationPrivate::app_style, className, palette(), qApp, QGuiApplication::setPalette(), and QApplicationPrivate::widgetPalettes.

Referenced by QApplicationPrivate::initializeWidgetPalettesFromTheme(), and QWindowsVistaStyle::polish().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setStartDragDistance()

void QApplication::setStartDragDistance ( int l)
static

Definition at line 2497 of file qapplication.cpp.

References QGuiApplication::styleHints().

+ Here is the call graph for this function:

◆ setStartDragTime()

void QApplication::setStartDragTime ( int ms)
static

Definition at line 2464 of file qapplication.cpp.

References QGuiApplication::styleHints().

+ Here is the call graph for this function:

◆ setStyle() [1/2]

QStyle * QApplication::setStyle ( const QString & style)
static

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Requests a QStyle object for style from the QStyleFactory.

The string must be one of the QStyleFactory::keys(), typically one of "windows", "windowsvista", "fusion", or "macos". Style names are case insensitive.

Returns \nullptr 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.

Definition at line 1071 of file qapplication.cpp.

References QStyleFactory::create(), setStyle(), and style().

+ Here is the call graph for this function:

◆ setStyle() [2/2]

void QApplication::setStyle ( QStyle * style)
static

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:

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 QStyle::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()

Definition at line 966 of file qapplication.cpp.

References allWidgets(), QApplicationPrivate::app_style, Qt::Desktop, QApplicationPrivate::focus_widget, QEvent::FocusIn, QApplicationPrivate::initializeWidgetFontHash(), QCoreApplicationPrivate::is_app_closing, QCoreApplicationPrivate::is_app_running, it, Qt::OtherFocusReason, QObject::parent(), qApp, qt_styleSheet(), QCoreApplication::sendEvent(), style(), QEvent::StyleChange, QApplicationPrivate::styleSheet, QGuiApplicationPrivate::updatePalette(), Qt::WA_SetStyle, and Qt::WA_WState_Polished.

Referenced by QApplicationPrivate::initialize(), main(), setStyle(), and setStyleSheet().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setStyleSheet

void QApplication::setStyleSheet ( const QString & sheet)
slot

Definition at line 878 of file qapplication.cpp.

References QApplicationPrivate::app_style, QString::isEmpty(), qApp, qt_styleSheet(), setStyle(), styleSheet, and QApplicationPrivate::styleSheet.

+ Here is the call graph for this function:

◆ startDragDistance()

static int QApplication::startDragDistance ( )
static

◆ startDragTime()

static int QApplication::startDragTime ( )
static

◆ style()

QStyle * QApplication::style ( )
static

Returns the application's style object.

See also
setStyle(), QStyle

Definition at line 902 of file qapplication.cpp.

References QApplicationPrivate::app_style, QStyleFactory::create(), QApplicationPrivate::desktopStyleKey(), QCoreApplication::instance(), QStyleFactory::keys(), Q_ASSERT, qApp, style(), QApplicationPrivate::styleSheet, and QGuiApplicationPrivate::updatePalette().

Referenced by QApplicationPrivate::applyQIconStyleHelper(), QWidget::changeEvent(), QMenuPrivate::copyActionToPlatformItem(), QDialogButtonBoxPrivate::createButton(), QItemDelegate::doCheck(), QItemDelegate::doLayout(), QItemDelegate::drawCheck(), QItemDelegate::drawDisplay(), QItemDelegate::drawFocus(), QStyledItemDelegate::editorEvent(), QWizardPrivate::ensureButton(), QFileIconProviderPrivate::getIcon(), QWidgetTextControl::getPaintContext(), QFormLayoutPrivate::getStyle(), QApplicationPrivate::initialize(), messageIcon2qIcon(), QStyledItemDelegate::paint(), QWidget::restoreGeometry(), QApplicationPrivate::setActiveWindow(), QWidgetTextControl::setCursorWidth(), setStyle(), setStyle(), QStyledItemDelegate::sizeHint(), QMessageBoxPrivate::standardIcon(), style(), QGraphicsLayoutStyleInfo::style(), QGraphicsScene::style(), QGraphicsWidget::style(), QWidget::style(), QGraphicsAnchorLayoutPrivate::styleInfo(), QItemDelegatePrivate::textLayoutBounds(), QItemDelegate::textRectangle(), QWidgetTextControl::timerEvent(), QMainWindowLayout::unplug(), and QStyledItemDelegate::updateEditorGeometry().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ styleSheet()

QString QApplication::styleSheet ( ) const

Definition at line 873 of file qapplication.cpp.

References QApplicationPrivate::styleSheet.

◆ topLevelAt() [1/2]

QWidget * QApplication::topLevelAt ( const QPoint & p)
static

Returns the top-level widget at the given point; returns \nullptr if there is no such widget.

Definition at line 294 of file qapplication.cpp.

References pos, QGuiApplication::topLevelAt(), and window().

Referenced by QApplicationPrivate::translateRawTouchEvent(), and widgetAt().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ topLevelAt() [2/2]

QWidget * QApplication::topLevelAt ( int x,
int y )
inlinestatic

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns the top-level widget at the point ({x}, {y}); returns 0 if there is no such widget.

Definition at line 90 of file qapplication.h.

References topLevelAt().

Referenced by topLevelAt().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ topLevelWidgets()

QWidgetList QApplication::topLevelWidgets ( )
static

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:

{
const QWidgetList topLevelWidgets = QApplication::topLevelWidgets();
for (QWidget *widget : topLevelWidgets) {
if (widget->isHidden())
}
}
See also
allWidgets(), QWidget::isWindow(), QWidget::isHidden()

Definition at line 1452 of file qapplication.cpp.

References QWidgetPrivate::allWidgets, Qt::Desktop, and list.

Referenced by QDialog::adjustPosition(), alert(), event(), QApplicationPrivate::notifyLayoutDirectionChange(), QWhatsThisPrivate::notifyToplevels(), QApplicationPrivate::notifyWindowIconChanged(), qt_tlw_for_window(), QApplicationPrivate::setActiveWindow(), and showAllHiddenTopLevelWidgets().

+ Here is the caller graph for this function:

◆ widgetAt() [1/2]

QWidget * QApplication::widgetAt ( const QPoint & point)
static

Returns the widget at global screen position point, or \nullptr if there is no Qt widget there.

This function can be slow.

See also
QCursor::pos(), QWidget::grabMouse(), QWidget::grabKeyboard()

Definition at line 734 of file qapplication.cpp.

References child, topLevelAt(), Qt::WA_TransparentForMouseEvents, widgetAt(), and window().

Referenced by QWhatsThisPrivate::QWhatsThisPrivate(), QCompleter::eventFilter(), QWidgetWindow::handleGestureEvent(), QWidgetWindow::handleMouseEvent(), PressDelayHandler::pressed(), QApplicationPrivate::sendMouseEvent(), and widgetAt().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ widgetAt() [2/2]

QWidget * QApplication::widgetAt ( int x,
int y )
inlinestatic

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns the widget at global screen position (x, y), or \nullptr if there is no Qt widget there.

Definition at line 88 of file qapplication.h.

References widgetAt().

Referenced by widgetAt().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ QAction

friend class QAction
friend

Definition at line 163 of file qapplication.h.

◆ QGestureManager

friend class QGestureManager
friend

Definition at line 166 of file qapplication.h.

◆ QGraphicsItem

friend class QGraphicsItem
friend

Definition at line 150 of file qapplication.h.

◆ QGraphicsScene

friend class QGraphicsScene
friend

Definition at line 151 of file qapplication.h.

◆ QGraphicsScenePrivate

friend class QGraphicsScenePrivate
friend

Definition at line 152 of file qapplication.h.

◆ QGraphicsWidget

friend class QGraphicsWidget
friend

Definition at line 149 of file qapplication.h.

◆ QLineEdit

friend class QLineEdit
friend

Definition at line 160 of file qapplication.h.

◆ QShortcut

friend class QShortcut
friend

Definition at line 159 of file qapplication.h.

◆ qt_sendSpontaneousEvent()

bool qt_sendSpontaneousEvent ( QObject * receiver,
QEvent * event )
related

\macro qApp

A global pointer referring to the unique application object. It is equivalent to QCoreApplication::instance(), but cast as a QApplication pointer, so only valid when the unique application object is a QApplication.

See also
QCoreApplication::instance(), qGuiApp

Definition at line 3684 of file qapplication.cpp.

◆ QTranslator

friend class QTranslator
friend

Definition at line 156 of file qapplication.h.

◆ QWidget

friend class QWidget
friend

Definition at line 153 of file qapplication.h.

◆ QWidgetAnimator

friend class QWidgetAnimator
friend

Definition at line 157 of file qapplication.h.

◆ QWidgetPrivate

friend class QWidgetPrivate
friend

Definition at line 154 of file qapplication.h.

◆ QWidgetTextControl

friend class QWidgetTextControl
friend

Definition at line 161 of file qapplication.h.

◆ QWidgetWindow

friend class QWidgetWindow
friend

Definition at line 155 of file qapplication.h.

Property Documentation

◆ autoSipEnabled

QApplication::autoSipEnabled
readwrite

toggles automatic SIP (software input panel) visibility

Since
4.5

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.

Definition at line 45 of file qapplication.h.

◆ cursorFlashTime

int QApplication::cursorFlashTime
readwrite

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 \uicontrol{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.

Definition at line 34 of file qapplication.h.

◆ doubleClickInterval

int QApplication::doubleClickInterval
readwrite

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.

Definition at line 35 of file qapplication.h.

Referenced by QAbstractItemView::edit(), QComboBoxPrivateContainer::eventFilter(), QWidgetTextControlPrivate::mouseDoubleClickEvent(), QLineEdit::mouseDoubleClickEvent(), QAbstractItemView::mousePressEvent(), and QComboBoxPrivate::showPopupFromMouseEvent().

◆ keyboardInputInterval

int QApplication::keyboardInputInterval
readwrite

the time limit in milliseconds that distinguishes a key press from two consecutive key presses

Since
4.2

The default value on X11 is 400 milliseconds. On Windows and Mac OS, the operating system's value is used.

Definition at line 36 of file qapplication.h.

Referenced by QAbstractItemView::keyboardSearch(), QTreeView::keyboardSearch(), and QMdiAreaPrivate::startTabToPreviousTimer().

◆ startDragDistance

int QApplication::startDragDistance
readwrite

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() >=
static void setStyle(QStyle *)
Sets the application's GUI style to style.
static QWidgetList topLevelWidgets()
Returns a list of the top-level widgets (windows) in the application.
int startDragDistance
the minimum distance required for a drag and drop operation to start.
static QWidgetList allWidgets()
Returns a list of all the widgets in the application.
\inmodule QtCore
static QStyle * create(const QString &)
bool isHidden() const
Returns true if the widget is hidden, otherwise returns false.
Definition qwidget.h:877
Q_CORE_EXPORT int qstrcmp(const char *str1, const char *str2)
void updateAllWidgets()
[4]
void showAllHiddenTopLevelWidgets()
[1]
QCoreApplication * createApplication(int &argc, char *argv[])
[0]

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(), QPoint::manhattanLength(), {Drag and Drop in Qt}{Drag and Drop}

Definition at line 41 of file qapplication.h.

Referenced by QMenuPrivate::hasMouseMoved(), QWidgetTextControlPrivate::mouseMoveEvent(), QLineEdit::mouseMoveEvent(), QTabBar::mouseMoveEvent(), QToolBarPrivate::mouseMoveEvent(), QtPrivate::QColorWell::mouseMoveEvent(), QtPrivate::QColorShowLabel::mouseMoveEvent(), QHeaderView::mouseMoveEvent(), QDockWidgetPrivate::mouseMoveEvent(), DragWidget::mouseMoveEvent(), FinalWidget::mouseMoveEvent(), QWidgetTextControlPrivate::mousePressEvent(), QLineEdit::mousePressEvent(), QToolBarAreaLayoutInfo::moveToolBar(), and src_gui_kernel_qapplication::wrapper1().

◆ startDragTime

int QApplication::startDragTime
readwrite

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
startDragDistance(), {Drag and Drop in Qt}{Drag and Drop}

Definition at line 40 of file qapplication.h.

Referenced by QLineEdit::mousePressEvent().

◆ styleSheet

QApplication::styleSheet
readwrite

the application style sheet

Since
4.2

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
QWidget::setStyle(), {Qt Style Sheets}

Definition at line 43 of file qapplication.h.

Referenced by setStyleSheet().


The documentation for this class was generated from the following files: