QApplication Class
The QApplication class manages the GUI application's control flow and main settings. More…
| Header | #include <QApplication> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Widgets) |
| Module | Nt Widgets C++ Classes |
| Inherits | QGuiApplication |
List of all members, including inherited members
Public Functions
| QApplication(int &argc, char **argv) | |
| ~QApplication() |
Public Slots
| void | closeAllWindows() |
Static Public Members
| QApplication * | instance() |
| QStyle * | style() |
| void | setStyle(QStyle *style) |
| QStyle * | setStyle(const QString &style) |
| QPalette | palette() |
| void | setPalette(const QPalette &palette) |
| QList<QWidget *> | topLevelWidgets() |
| QList<QWidget *> | allWidgets() |
| QWidget * | activeWindow() |
| QWidget * | activeModalWidget() |
| QWidget * | focusWidget() |
| QWidget * | widgetAt(const QPoint &point) |
Detailed Description
QApplication is a QGuiApplication that also knows about widgets: it owns the style and the default palette, and lists the top-level widgets. Create it before any widget:
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QPushButton button("Quit");
QObject::connect(&button, &QPushButton::clicked, &app, &QApplication::quit);
button.show();
return app.exec();
}
The application quits when the last window is closed, as QGuiApplication does.
See also QGuiApplication and QWidget.
Differences from Qt
There are no setStyleSheet(), setActiveWindow(), setFont() for classes, beep(), alert(), setWindowIcon(), cursor overrides, double click interval, focusChanged() signal or style factory.
Member Function Documentation
QApplication::QApplication(int &argc, char **argv)
Constructs a widget application from argc and argv, as QGuiApplication does.
QApplication::~QApplication()
Destroys the application object and the style.
QWidget * QApplication::activeModalWidget()
Returns the modal window that was shown last and is still shown, or nullptr if no modal window is shown.
See also QWidget::setWindowModality().
QWidget * QApplication::activeWindow()
Returns the top-level widget whose window is the active window, or nullptr.
See also focusWidget().
QList<QWidget *> QApplication::allWidgets()
Returns all widgets of the application, windows and their descendants.
See also topLevelWidgets().
void QApplication::closeAllWindows()
Closes all top-level windows. The application quits if the last one closed and QGuiApplication::quitOnLastWindowClosed() is true.
See also QWidget::close().
QWidget * QApplication::focusWidget()
Returns the widget that has the keyboard focus: the focus widget of the active window, or nullptr.
See also activeWindow().
QApplication * QApplication::instance()
Returns the application object, or nullptr if there is none or it is not a QApplication.
QPalette QApplication::palette()
Returns the default palette, which widgets use unless they or an ancestor have their own. Unless setPalette() set one, it is the standardPalette() of the style, which follows the color scheme of the desktop: widgets turn dark when the desktop does.
See also setPalette(), QStyle::standardPalette() and QStyleHints::colorScheme().
void QApplication::setPalette(const QPalette &palette)
Sets the default palette to palette. Widgets that have no palette of their own are painted again. Passing a default-constructed QPalette restores the standard palette of the style, which follows the color scheme of the desktop again.
See also palette() and QStyle::standardPalette().
void QApplication::setStyle(QStyle *style)
Makes style the style of the application, which takes ownership of it. A nullptr restores the default style. Widgets are drawn again.
See also style().
QStyle * QApplication::setStyle(const QString &style)
This is an overloaded function.
Makes the style called style the style of the application, and returns it; QStyleFactory::keys() lists the names. Returns nullptr, and leaves the style as it is, if there is no style of that name.
See also QStyleFactory::create().
QStyle * QApplication::style()
Returns the style of the application, which draws every widget that has no style of its own. It is the default style until setStyle() changes it.
See also setStyle() and QWidget::style().
QList<QWidget *> QApplication::topLevelWidgets()
Returns the widgets that have no parent, windows, whether they are visible or not.
See also allWidgets().
QWidget * QApplication::widgetAt(const QPoint &point)
Returns the visible widget at point, in screen coordinates, or nullptr if there is none.