Qt 6.x
The Qt SDK
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
qapplication.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qplatformdefs.h"
6#include "qapplication.h"
7#include "qclipboard.h"
8#include "qcursor.h"
9#include "qdir.h"
10#include "qevent.h"
11#include "qfile.h"
12#include "qfileinfo.h"
13#if QT_CONFIG(graphicsview)
14#include "qgraphicsscene.h"
15#include <QtWidgets/qgraphicsproxywidget.h>
16#endif
17#include "qhash.h"
18#include "qset.h"
19#include "qlayout.h"
20#include "qpixmapcache.h"
21#include "qstyle.h"
22#include "qstyleoption.h"
23#include "qstylefactory.h"
24#if QT_CONFIG(tooltip)
25#include "qtooltip.h"
26#endif
27#include "qtranslator.h"
28#include "qvariant.h"
29#include "qwidget.h"
30#if QT_CONFIG(draganddrop)
31#include <private/qdnd_p.h>
32#endif
33#include "private/qguiapplication_p.h"
34#include "qcolormap.h"
35#include "qdebug.h"
36#include "private/qstylesheetstyle_p.h"
37#include "private/qstyle_p.h"
38#if QT_CONFIG(messagebox)
39#include "qmessagebox.h"
40#endif
41#include "qwidgetwindow_p.h"
42#include <QtGui/qstylehints.h>
43#include <QtGui/qinputmethod.h>
44#include <QtGui/private/qwindow_p.h>
45#include <QtGui/qpointingdevice.h>
46#include <QtGui/private/qpointingdevice_p.h>
47#include <qpa/qplatformtheme.h>
48#if QT_CONFIG(whatsthis)
49#include <QtWidgets/QWhatsThis>
50#endif
51#if QT_CONFIG(accessibility)
52#include <QtGui/qaccessible_base.h>
53#include "private/qaccessiblewidgetfactory_p.h"
54#endif
55
56#include "private/qkeymapper_p.h"
57
58#include <qthread.h>
59#include <private/qthread_p.h>
60
61#include <QtGui/private/qevent_p.h>
62#include <QtGui/private/qeventpoint_p.h>
63#include <private/qfont_p.h>
64#if QT_CONFIG(action)
65#include <private/qaction_p.h>
66#endif
67
68#include <stdlib.h>
69
70#include "qapplication_p.h"
71#include "qwidget_p.h"
72
73#include "qgesture.h"
74#include "private/qgesturemanager_p.h"
75#include <qpa/qplatformfontdatabase.h>
76
77#include "qdatetime.h"
78
79#include <qpa/qplatformwindow.h>
80
81#include <qtwidgets_tracepoints_p.h>
82
83#ifdef Q_OS_MACOS
84#include <QtCore/private/qcore_mac_p.h>
85#endif
86
87#include <algorithm>
88#include <iterator>
89
90static void initResources()
91{
92 Q_INIT_RESOURCE(qstyle);
93
94#if QT_CONFIG(messagebox)
95 Q_INIT_RESOURCE(qmessagebox);
96#endif
97}
98
100
101using namespace Qt::StringLiterals;
102
104 "#include <qcoreevent.h>"
105);
106Q_TRACE_METADATA(qtwidgets, "ENUM { AUTO, RANGE User ... MaxUser } QEvent::Type;");
107Q_TRACE_POINT(qtwidgets, QApplication_notify_entry, QObject *receiver, QEvent *event, QEvent::Type type);
108Q_TRACE_POINT(qtwidgets, QApplication_notify_exit, bool consumed, bool filtered);
109
110// Helper macro for static functions to check on the existence of the application class.
111#define CHECK_QAPP_INSTANCE(...) \
112 if (Q_LIKELY(QCoreApplication::instance())) { \
113 } else { \
114 qWarning("Must construct a QApplication first."); \
115 return __VA_ARGS__; \
116 }
117
118Q_CORE_EXPORT void qt_call_post_routines();
119Q_GUI_EXPORT bool qt_sendShortcutOverrideEvent(QObject *o, ulong timestamp, int k, Qt::KeyboardModifiers mods, const QString &text = QString(), bool autorep = false, ushort count = 1);
120
121QApplicationPrivate *QApplicationPrivate::self = nullptr;
122
124
126 : QGuiApplicationPrivate(argc, argv)
127{
129
130#ifndef QT_NO_GESTURES
131 gestureManager = nullptr;
132 gestureWidget = nullptr;
133#endif // QT_NO_GESTURES
134
135 if (!self)
136 self = this;
137}
138
140{
141 if (self == this)
142 self = nullptr;
143}
144
146{
148}
149
295{
297 if (const QWidgetWindow *widgetWindow = qobject_cast<const QWidgetWindow *>(window))
298 return widgetWindow->widget();
299 }
300 return nullptr;
301}
302
313void qt_cleanup();
314
315QStyle *QApplicationPrivate::app_style = nullptr; // default application style
316#ifndef QT_NO_STYLE_STYLESHEET
317QString QApplicationPrivate::styleSheet; // default application stylesheet
318#endif
320
321QFont *QApplicationPrivate::sys_font = nullptr; // default system font
322QFont *QApplicationPrivate::set_font = nullptr; // default font set by programmer
323
324QWidget *QApplicationPrivate::main_widget = nullptr; // main application widget
325QWidget *QApplicationPrivate::focus_widget = nullptr; // has keyboard input focus
326QWidget *QApplicationPrivate::hidden_focus_widget = nullptr; // will get keyboard input focus after show()
327QWidget *QApplicationPrivate::active_window = nullptr; // toplevel with keyboard focus
328#if QT_CONFIG(wheelevent)
329QPointer<QWidget> QApplicationPrivate::wheel_widget;
330#endif
335#ifdef QT_KEYPAD_NAVIGATION
336Qt::NavigationMode QApplicationPrivate::navigationMode = Qt::NavigationModeKeypadTabOrder;
337QWidget *QApplicationPrivate::oldEditFocus = nullptr;
338#endif
339
340inline bool QApplicationPrivate::isAlien(QWidget *widget)
341{
342 return widget && !widget->isWindow();
343}
344
345bool Q_WIDGETS_EXPORT qt_tab_all_widgets()
346{
348}
349
350// ######## move to QApplicationPrivate
351// Default fonts (per widget type)
352Q_GLOBAL_STATIC(FontHash, app_fonts)
353// Exported accessor for use outside of this file
354FontHash *qt_app_fonts_hash() { return app_fonts(); }
355
356QWidgetList *QApplicationPrivate::popupWidgets = nullptr; // has keyboard input focus
357
358QWidget *qt_desktopWidget = nullptr; // root window widgets
359
364{
365 if (styleOverride.isEmpty() && qEnvironmentVariableIsSet("QT_STYLE_OVERRIDE"))
366 styleOverride = QString::fromLocal8Bit(qgetenv("QT_STYLE_OVERRIDE"));
367
368 // process platform-indep command line
369 if (qt_is_tty_app || !argc)
370 return;
371
372 int i, j;
373
374 j = 1;
375 for (i=1; i<argc; i++) { // if you add anything here, modify QCoreApplication::arguments()
376 if (!argv[i])
377 continue;
378 if (*argv[i] != '-') {
379 argv[j++] = argv[i];
380 continue;
381 }
382 const char *arg = argv[i];
383 if (arg[1] == '-') // startsWith("--")
384 ++arg;
385 if (strcmp(arg, "-qdevel") == 0 || strcmp(arg, "-qdebug") == 0) {
386 // obsolete argument
387#ifndef QT_NO_STYLE_STYLESHEET
388 } else if (strcmp(arg, "-stylesheet") == 0 && i < argc -1) {
389 styleSheet = "file:///"_L1;
391 } else if (strncmp(arg, "-stylesheet=", 12) == 0) {
392 styleSheet = "file:///"_L1;
394#endif
395 } else if (qstrcmp(arg, "-widgetcount") == 0) {
396 widgetCount = true;
397 } else {
398 argv[j++] = argv[i];
399 }
400 }
401
402 if (j < argc) {
403 argv[j] = nullptr;
404 argc = j;
405 }
406}
407
453#ifdef Q_QDOC
454QApplication::QApplication(int &argc, char **argv)
455#else
456QApplication::QApplication(int &argc, char **argv, int)
457#endif
458 : QGuiApplication(*new QApplicationPrivate(argc, argv))
459{
460 Q_D(QApplication);
461 d->init();
462}
463
468{
469#if defined(Q_OS_MACOS)
471#endif
472
474
476
479
480 // Must be called before initialize()
485
486 initialize();
488
489#if QT_CONFIG(accessibility)
490 // factory for accessible interfaces for widgets shipped with Qt
491 QAccessible::installFactory(&qAccessibleFactory);
492#endif
493
494}
495
497{
498#if QT_CONFIG(tooltip)
501#endif
502}
503
504extern void qRegisterWidgetsVariant();
505
510{
511 is_app_running = false; // Starting up.
512
515
516 // needed for a static build.
518
519 // needed for widgets in QML
521
523 if (!styleOverride.isEmpty()) {
524 if (auto *style = QStyleFactory::create(styleOverride.toLower())) {
526 } else {
527 qWarning("QApplication: invalid style override '%s' passed, ignoring it.\n"
528 "\tAvailable styles: %s", qPrintable(styleOverride),
529 qPrintable(QStyleFactory::keys().join(", "_L1)));
530 // Clear styleOverride so it is not picked by Qt Quick Controls (QTBUG-100563)
532 }
533 }
534
535 // Trigger default style if none was set already
537 }
538
539 if (qEnvironmentVariableIntValue("QT_USE_NATIVE_WINDOWS") > 0)
541
542 if (!qt_is_tty_app)
544
548 }
549
550 is_app_running = true; // no longer starting up
551}
552
554{
556 if (!theme)
557 return;
558 FontHash *fontHash = app_fonts();
559 fontHash->clear();
560
561 if (const QFont *font = theme->font(QPlatformTheme::MenuFont))
562 fontHash->insert(QByteArrayLiteral("QMenu"), *font);
563 if (const QFont *font = theme->font(QPlatformTheme::MenuBarFont))
564 fontHash->insert(QByteArrayLiteral("QMenuBar"), *font);
565 if (const QFont *font = theme->font(QPlatformTheme::MenuItemFont))
566 fontHash->insert(QByteArrayLiteral("QMenuItem"), *font);
567 if (const QFont *font = theme->font(QPlatformTheme::MessageBoxFont))
568 fontHash->insert(QByteArrayLiteral("QMessageBox"), *font);
569 if (const QFont *font = theme->font(QPlatformTheme::LabelFont))
570 fontHash->insert(QByteArrayLiteral("QLabel"), *font);
571 if (const QFont *font = theme->font(QPlatformTheme::TipLabelFont))
572 fontHash->insert(QByteArrayLiteral("QTipLabel"), *font);
573 if (const QFont *font = theme->font(QPlatformTheme::TitleBarFont))
574 fontHash->insert(QByteArrayLiteral("QTitleBar"), *font);
575 if (const QFont *font = theme->font(QPlatformTheme::StatusBarFont))
576 fontHash->insert(QByteArrayLiteral("QStatusBar"), *font);
578 fontHash->insert(QByteArrayLiteral("QMdiSubWindowTitleBar"), *font);
580 fontHash->insert(QByteArrayLiteral("QDockWidgetTitle"), *font);
581 if (const QFont *font = theme->font(QPlatformTheme::PushButtonFont))
582 fontHash->insert(QByteArrayLiteral("QPushButton"), *font);
583 if (const QFont *font = theme->font(QPlatformTheme::CheckBoxFont))
584 fontHash->insert(QByteArrayLiteral("QCheckBox"), *font);
585 if (const QFont *font = theme->font(QPlatformTheme::RadioButtonFont))
586 fontHash->insert(QByteArrayLiteral("QRadioButton"), *font);
587 if (const QFont *font = theme->font(QPlatformTheme::ToolButtonFont))
588 fontHash->insert(QByteArrayLiteral("QToolButton"), *font);
589 if (const QFont *font = theme->font(QPlatformTheme::ItemViewFont))
590 fontHash->insert(QByteArrayLiteral("QAbstractItemView"), *font);
591 if (const QFont *font = theme->font(QPlatformTheme::ListViewFont))
592 fontHash->insert(QByteArrayLiteral("QListView"), *font);
593 if (const QFont *font = theme->font(QPlatformTheme::HeaderViewFont))
594 fontHash->insert(QByteArrayLiteral("QHeaderView"), *font);
595 if (const QFont *font = theme->font(QPlatformTheme::ListBoxFont))
596 fontHash->insert(QByteArrayLiteral("QListBox"), *font);
598 fontHash->insert(QByteArrayLiteral("QComboMenuItem"), *font);
600 fontHash->insert(QByteArrayLiteral("QComboLineEdit"), *font);
601 if (const QFont *font = theme->font(QPlatformTheme::SmallFont))
602 fontHash->insert(QByteArrayLiteral("QSmallFont"), *font);
603 if (const QFont *font = theme->font(QPlatformTheme::MiniFont))
604 fontHash->insert(QByteArrayLiteral("QMiniFont"), *font);
605}
606
607/*****************************************************************************
608 Functions returning the active popup and modal widgets.
609 *****************************************************************************/
610
627{
630}
631
632
648{
649 QWidgetWindow *widgetWindow = qobject_cast<QWidgetWindow *>(modalWindow());
650 return widgetWindow ? widgetWindow->widget() : nullptr;
651}
652
659{
660 Q_D(QApplication);
661
662 //### this should probable be done even later
664
665 // kill timers before closing down the dispatcher
666 d->toolTipWakeUp.stop();
667 d->toolTipFallAsleep.stop();
668
671
673 QWidgetPrivate::mapper = nullptr;
674
675 // delete all widgets
679 for (QWidgetSet::ConstIterator it = mySet->constBegin(), cend = mySet->constEnd(); it != cend; ++it) {
680 QWidget *w = *it;
681 if (!w->parent()) // window
682 w->destroy(true, true);
683 }
684 delete mySet;
685 }
686
687 delete qt_desktopWidget;
688 qt_desktopWidget = nullptr;
689
691
696 app_fonts()->clear();
697
700
701#if QT_CONFIG(draganddrop)
702 if (!qt_is_tty_app)
703 delete QDragManager::self();
704#endif
705
706 d->cleanupMultitouch();
707
708 qt_cleanup();
709
711 qDebug("Widgets left: %i Max widgets: %i \n", QWidgetPrivate::instanceCounter, QWidgetPrivate::maxInstances);
712
714
717}
718
720{
723
724 QApplicationPrivate::active_window = nullptr; //### this should not be necessary
725}
726
738{
740 if (!window)
741 return nullptr;
742
743 QWidget *child = nullptr;
744
745 if (!window->testAttribute(Qt::WA_TransparentForMouseEvents))
746 child = window->childAt(window->mapFromGlobal(p));
747
748 if (child)
749 return child;
750
751 if (window->testAttribute(Qt::WA_TransparentForMouseEvents)) {
752 //shoot a hole in the widget and try once again,
753 //suboptimal on Qt for Embedded Linux where we do
754 //know the stacking order of the toplevels.
755 int x = p.x();
756 int y = p.y();
757 QRegion oldmask = window->mask();
758 QPoint wpoint = window->mapFromGlobal(QPoint(x, y));
759 QRegion newmask = (oldmask.isEmpty() ? QRegion(window->rect()) : oldmask)
760 - QRegion(wpoint.x(), wpoint.y(), 1, 1);
761 window->setMask(newmask);
762 QWidget *recurse = nullptr;
763 if (QApplication::topLevelAt(p) != window) // verify recursion will terminate
764 recurse = widgetAt(x, y);
765 if (oldmask.isEmpty())
766 window->clearMask();
767 else
768 window->setMask(oldmask);
769 return recurse;
770 }
771 return window;
772}
773
787{
788 // Only compress the following events:
789 const QEvent::Type type = event->type();
790 switch (type) {
793 case QEvent::Resize:
794 case QEvent::Move:
796 break;
797 default:
798 return QGuiApplication::compressEvent(event, receiver, postedEvents);
799 }
800
801 for (const auto &postedEvent : std::as_const(*postedEvents)) {
802
803 // Continue, unless a valid event of the same type exists for the same receiver
804 if (postedEvent.receiver != receiver
805 || !postedEvent.event
806 || postedEvent.event->type() != type) {
807 continue;
808 }
809
810 // Handle type specific compression
811 switch (type) {
812 case QEvent::Resize:
813 static_cast<QResizeEvent *>(postedEvent.event)->m_size =
814 static_cast<const QResizeEvent *>(event)->size();
815 break;
816 case QEvent::Move:
817 static_cast<QMoveEvent *>(postedEvent.event)->m_pos =
818 static_cast<const QMoveEvent *>(event)->pos();
819 break;
823 break;
824 default:
825 continue;
826 }
827 delete event;
828 return true;
829 }
830 return false;
831}
832
860{
862}
863
865{
867}
868
869#ifndef QT_NO_STYLE_STYLESHEET
870
872{
874}
875
877{
880 if (styleSheet.isEmpty()) { // application style sheet removed
881 if (!styleSheetStyle)
882 return; // there was no stylesheet before
883 setStyle(styleSheetStyle->base);
884 } else if (styleSheetStyle) { // style sheet update, just repolish
885 styleSheetStyle->repolish(qApp);
886 } else { // stylesheet set the first time
888 QApplicationPrivate::app_style->setParent(newStyleSheetStyle);
889 setStyle(newStyleSheetStyle);
890 }
891}
892
893#endif // QT_NO_STYLE_STYLESHEET
894
901{
903 // Create default style
904 if (!qobject_cast<QApplication *>(QCoreApplication::instance())) {
905 Q_ASSERT(!"No style available without QApplication!");
906 return nullptr;
907 }
908
909 auto &defaultStyle = QApplicationPrivate::app_style;
910
912 if (!defaultStyle) {
913 const QStringList styles = QStyleFactory::keys();
914 for (const auto &style : styles) {
915 if ((defaultStyle = QStyleFactory::create(style)))
916 break;
917 }
918 }
919 if (!defaultStyle) {
920 Q_ASSERT(!"No styles available!");
921 return nullptr;
922 }
923
924 // Take ownership of the style
925 defaultStyle->setParent(qApp);
926
928
929#ifndef QT_NO_STYLE_STYLESHEET
930 if (!QApplicationPrivate::styleSheet.isEmpty()) {
932 } else
933#endif
934 {
935 defaultStyle->polish(qApp);
936 }
937 }
938
940}
941
965{
967 return;
968
969 QWidgetList all = allWidgets();
970
971 // clean up the old style
974 for (QWidgetList::ConstIterator it = all.constBegin(), cend = all.constEnd(); it != cend; ++it) {
975 QWidget *w = *it;
976 if (!(w->windowType() == Qt::Desktop) && // except desktop
977 w->testAttribute(Qt::WA_WState_Polished)) { // has been polished
979 }
980 }
981 }
983 }
984
986
987#ifndef QT_NO_STYLE_STYLESHEET
989 // we have a stylesheet already and a new style is being set
990 QStyleSheetStyle *newStyleSheetStyle = new QStyleSheetStyle(style);
991 style->setParent(newStyleSheetStyle);
992 QApplicationPrivate::app_style = newStyleSheetStyle;
993 } else
994#endif // QT_NO_STYLE_STYLESHEET
997
998 // Take care of possible palette requirements of certain
999 // styles. Do it before polishing the application since the
1000 // style might call QApplication::setPalette() itself.
1002
1003 // The default widget font hash is based on the platform theme,
1004 // not the style, but the widget fonts could in theory have been
1005 // affected by polish of the previous style, without a proper
1006 // cleanup in unpolish, so reset it now before polishing the
1007 // new style.
1009
1010 // initialize the application with the new style
1012
1013 // re-polish existing widgets if necessary
1015 for (QWidgetList::ConstIterator it = all.constBegin(), cend = all.constEnd(); it != cend; ++it) {
1016 QWidget *w = *it;
1017 if (w->windowType() != Qt::Desktop && w->testAttribute(Qt::WA_WState_Polished)) {
1018 if (w->style() == QApplicationPrivate::app_style)
1019 QApplicationPrivate::app_style->polish(w); // repolish
1020#ifndef QT_NO_STYLE_STYLESHEET
1021 else
1022 w->setStyleSheet(w->styleSheet()); // touch
1023#endif
1024 }
1025 }
1026
1027 for (QWidgetList::ConstIterator it = all.constBegin(), cend = all.constEnd(); it != cend; ++it) {
1028 QWidget *w = *it;
1029 if (w->windowType() != Qt::Desktop && !w->testAttribute(Qt::WA_SetStyle)) {
1032 w->update();
1033 }
1034 }
1035 }
1036
1037#ifndef QT_NO_STYLE_STYLESHEET
1038 if (QStyleSheetStyle *oldStyleSheetStyle = qt_styleSheet(old)) {
1039 oldStyleSheetStyle->deref();
1040 } else
1041#endif
1042 if (old && old->parent() == qApp) {
1043 delete old;
1044 }
1045
1050 }
1051}
1052
1070{
1072 if (!s)
1073 return nullptr;
1074
1075 setStyle(s);
1076 return s;
1077}
1078
1079// Widget specific palettes
1081
1083{
1084 // Start out with a palette based on the style, in case there's no theme
1085 // available, or so that we can fill in missing roles in the theme.
1087
1088 // Prefer theme palette if available, but fill in missing roles from style
1089 // for compatibility. Note that the style's standard palette is not prioritized
1090 // over the theme palette, as the documented way of applying the style's palette
1091 // is to set it explicitly using QApplication::setPalette().
1092 if (const QPalette *themePalette = platformTheme() ? platformTheme()->palette() : nullptr)
1093 palette = themePalette->resolve(palette);
1094
1095 // Finish off by letting the application style polish the palette. This will
1096 // not result in the polished palette becoming a user-set palette, as the
1097 // resulting base palette is only used as a fallback, with the resolve mask
1098 // set to 0.
1099 if (app_style)
1101
1102 return palette;
1103}
1104
1117{
1118 auto &widgetPalettes = QApplicationPrivate::widgetPalettes;
1119 if (w && !widgetPalettes.isEmpty()) {
1120 auto it = widgetPalettes.constFind(w->metaObject()->className());
1121 const auto cend = widgetPalettes.constEnd();
1122 if (it != cend)
1123 return *it;
1124 for (it = widgetPalettes.constBegin(); it != cend; ++it) {
1125 if (w->inherits(it.key()))
1126 return it.value();
1127 }
1128 }
1129 return palette();
1130}
1131
1140{
1141 auto &widgetPalettes = QApplicationPrivate::widgetPalettes;
1142 if (className && !widgetPalettes.isEmpty()) {
1143 auto it = widgetPalettes.constFind(className);
1144 if (it != widgetPalettes.constEnd())
1145 return *it;
1146 }
1147
1148 return QGuiApplication::palette();
1149}
1150
1174{
1175 if (className) {
1176 QPalette polishedPalette = palette;
1178 auto originalResolveMask = palette.resolveMask();
1179 QApplicationPrivate::app_style->polish(polishedPalette);
1180 polishedPalette.setResolveMask(originalResolveMask);
1181 }
1182
1184 if (qApp)
1185 qApp->d_func()->handlePaletteChanged(className);
1186 } else {
1188 }
1189}
1190
1192{
1194 return;
1195
1196 // Setting the global application palette is documented to
1197 // reset any previously set class specific widget palettes.
1198 if (!className && !widgetPalettes.isEmpty())
1200
1202
1205 for (auto widget : widgets) {
1208 }
1209
1210#if QT_CONFIG(graphicsview)
1211 for (auto scene : std::as_const(scene_list))
1213#endif
1214
1215 // Palette has been reset back to the default application palette,
1216 // so we need to reinitialize the widget palettes from the theme.
1219}
1220
1222{
1224 if (!platformTheme)
1225 return;
1226
1228
1229 struct ThemedWidget { const char *className; QPlatformTheme::Palette palette; };
1230
1231 static const ThemedWidget themedWidgets[] = {
1232 { "QToolButton", QPlatformTheme::ToolButtonPalette },
1233 { "QAbstractButton", QPlatformTheme::ButtonPalette },
1234 { "QCheckBox", QPlatformTheme::CheckBoxPalette },
1235 { "QRadioButton", QPlatformTheme::RadioButtonPalette },
1236 { "QHeaderView", QPlatformTheme::HeaderPalette },
1237 { "QAbstractItemView", QPlatformTheme::ItemViewPalette },
1238 { "QMessageBoxLabel", QPlatformTheme::MessageBoxLabelPalette },
1239 { "QTabBar", QPlatformTheme::TabBarPalette },
1240 { "QLabel", QPlatformTheme::LabelPalette },
1241 { "QGroupBox", QPlatformTheme::GroupBoxPalette },
1242 { "QMenu", QPlatformTheme::MenuPalette },
1243 { "QMenuBar", QPlatformTheme::MenuBarPalette },
1244 { "QTextEdit", QPlatformTheme::TextEditPalette },
1245 { "QTextControl", QPlatformTheme::TextEditPalette },
1246 { "QLineEdit", QPlatformTheme::TextLineEditPalette },
1247 };
1248
1249 for (const auto themedWidget : themedWidgets) {
1250 if (auto *palette = platformTheme->palette(themedWidget.palette))
1251 QApplication::setPalette(*palette, themedWidget.className);
1252 }
1253}
1254
1261{
1262 return QGuiApplication::font();
1263}
1264
1276{
1277 typedef FontHash::const_iterator FontHashConstIt;
1278
1279 FontHash *hash = app_fonts();
1280
1281 if (widget && hash && hash->size()) {
1282#ifdef Q_OS_MAC
1283 // short circuit for small and mini controls
1285 return hash->value(QByteArrayLiteral("QSmallFont"));
1287 return hash->value(QByteArrayLiteral("QMiniFont"));
1288 }
1289#endif
1290 // Return the font for the nearest registered superclass
1291 const QMetaObject *metaObj = widget->metaObject();
1292 FontHashConstIt it = hash->constFind(metaObj->className());
1293 const FontHashConstIt cend = hash->constEnd();
1294 while (it == cend && metaObj != &QWidget::staticMetaObject) {
1295 metaObj = metaObj->superClass();
1296 it = hash->constFind(metaObj->className());
1297 }
1298 if (it != cend)
1299 return it.value();
1300 }
1301 return font();
1302}
1303
1312{
1313 FontHash *hash = app_fonts();
1314 if (className && hash && hash->size()) {
1316 if (it != hash->constEnd())
1317 return *it;
1318 }
1319 return font();
1320}
1321
1322
1343{
1344 FontHash *hash = app_fonts();
1345 if (!className) {
1347 if (hash && hash->size())
1348 hash->clear();
1349 } else if (hash) {
1350 hash->insert(className, font);
1351 }
1355 for (QWidgetList::ConstIterator it = wids.constBegin(), cend = wids.constEnd(); it != cend; ++it) {
1356 QWidget *w = *it;
1357 if (!w->isWindow() && w->inherits(className)) // matching class
1358 sendEvent(w, &e);
1359 }
1360
1361#if QT_CONFIG(graphicsview)
1362 // Send to all scenes as well.
1363 QList<QGraphicsScene *> &scenes = qApp->d_func()->scene_list;
1365 it != scenes.constEnd(); ++it) {
1367 }
1368#endif // QT_CONFIG(graphicsview)
1369 }
1373 else
1375 }
1376}
1377
1381{
1382 if (!sys_font)
1383 sys_font = new QFont(font);
1384 else
1385 *sys_font = font;
1386
1389}
1390
1394{
1395#if defined(QT_BUILD_INTERNAL)
1396 // Allow auto-tests to override the desktop style
1397 if (qEnvironmentVariableIsSet("QT_DESKTOP_STYLE_KEY"))
1398 return QString::fromLocal8Bit(qgetenv("QT_DESKTOP_STYLE_KEY"));
1399#endif
1400
1401 // The platform theme might return a style that is not available, find
1402 // first valid one.
1404 const QStringList availableKeys = QStyleFactory::keys();
1405 const auto styles = theme->themeHint(QPlatformTheme::StyleNames).toStringList();
1406 for (const QString &style : styles) {
1407 if (availableKeys.contains(style, Qt::CaseInsensitive))
1408 return style;
1409 }
1410 }
1411 return QString();
1412}
1413
1415{
1419
1420 // send to all top-level QWidgets
1421 for (auto *w : list) {
1422 windowList.removeOne(w->windowHandle());
1424 }
1425
1426 // in case there are any plain QWindows in this QApplication-using
1427 // application, also send the notification to them
1428 for (int i = 0; i < windowList.size(); ++i)
1429 QCoreApplication::sendEvent(windowList.at(i), &ev);
1430}
1431
1445{
1447 if (QWidgetPrivate::allWidgets != nullptr) {
1448 const auto isTopLevelWidget = [] (const QWidget *w) {
1449 return w->isWindow() && w->windowType() != Qt::Desktop;
1450 };
1451 std::copy_if(QWidgetPrivate::allWidgets->cbegin(), QWidgetPrivate::allWidgets->cend(),
1452 std::back_inserter(list), isTopLevelWidget);
1453 }
1454 return list;
1455}
1456
1471{
1474 return QWidgetList();
1475}
1476
1485{
1487}
1488
1490{
1491#if QT_CONFIG(graphicsview)
1492 if (focus && focus->window()->graphicsProxyWidget())
1493 return;
1494#endif
1495
1496 hidden_focus_widget = nullptr;
1497
1498 if (focus != focus_widget) {
1499 if (focus && focus->isHidden()) {
1501 return;
1502 }
1503
1504 if (focus && (reason == Qt::BacktabFocusReason || reason == Qt::TabFocusReason)
1506 focus->window()->setAttribute(Qt::WA_KeyboardFocusChange);
1507 else if (focus && reason == Qt::ShortcutFocusReason) {
1508 focus->window()->setAttribute(Qt::WA_KeyboardFocusChange);
1509 }
1510 QWidget *prev = focus_widget;
1512
1513 if (focus_widget)
1514 focus_widget->d_func()->setFocus_sys();
1515
1516 if (reason != Qt::NoFocusReason) {
1517
1518 //send events
1519 if (prev) {
1520#ifdef QT_KEYPAD_NAVIGATION
1521 if (QApplicationPrivate::keyboardNavigationEnabled()) {
1522 if (prev->hasEditFocus() && reason != Qt::PopupFocusReason)
1523 prev->setEditFocus(false);
1524 }
1525#endif
1527 QPointer<QWidget> that = prev;
1529 if (that)
1530 QCoreApplication::sendEvent(that->style(), &out);
1531 }
1534 QPointer<QWidget> that = focus;
1536 if (that)
1537 QCoreApplication::sendEvent(that->style(), &in);
1538 }
1539 emit qApp->focusChanged(prev, focus_widget);
1540 }
1541 }
1542}
1543
1544
1555{
1557}
1558
1559#if QT_DEPRECATED_SINCE(6,0)
1567QFontMetrics QApplication::fontMetrics()
1568{
1570}
1571#endif
1572
1573bool QApplicationPrivate::tryCloseAllWidgetWindows(QWindowList *processedWindows)
1574{
1575 Q_ASSERT(processedWindows);
1577 if (!w->isVisible() || w->data->is_closing)
1578 break;
1579 QWindow *window = w->windowHandle();
1580 if (!window->close()) // Qt::WA_DeleteOnClose may cause deletion.
1581 return false;
1582 if (window)
1583 processedWindows->append(window);
1584 }
1585
1586retry:
1588 for (auto *w : list) {
1589 if (w->isVisible() && w->windowType() != Qt::Desktop &&
1590 !w->testAttribute(Qt::WA_DontShowOnScreen) && !w->data->is_closing) {
1591 QWindow *window = w->windowHandle();
1592 if (!window->close()) // Qt::WA_DeleteOnClose may cause deletion.
1593 return false;
1594 if (window)
1595 processedWindows->append(window);
1596 goto retry;
1597 }
1598 }
1599 return true;
1600}
1601
1619{
1620 QWindowList processedWindows;
1621 QApplicationPrivate::tryCloseAllWidgetWindows(&processedWindows);
1622}
1623
1634{
1635#if QT_CONFIG(messagebox)
1637#endif // QT_CONFIG(messagebox)
1638}
1639
1659{
1660 Q_D(QApplication);
1661 switch (e->type()) {
1662 case QEvent::Quit:
1663 // FIXME: This logic first tries to close all windows, and then
1664 // checks whether it was successful, but the conditions used in
1665 // closeAllWindows() differ from the verification logic below.
1666 // We should build on the logic in tryCloseAllWidgetWindows().
1668 for (auto *w : topLevelWidgets()) {
1669 if (w->data->is_closing)
1670 continue;
1671 if (w->isVisible() && !(w->windowType() == Qt::Desktop) && !(w->windowType() == Qt::Popup) &&
1672 (!(w->windowType() == Qt::Dialog) || !w->parentWidget()) && !w->testAttribute(Qt::WA_DontShowOnScreen)) {
1673 e->ignore();
1674 return true;
1675 }
1676 }
1677 // Explicitly call QCoreApplication instead of QGuiApplication so that
1678 // we don't let QGuiApplication close any windows we skipped earlier in
1679 // closeAllWindows(). FIXME: Unify all this close magic through closeAllWindows.
1680 return QCoreApplication::event(e);
1681#ifndef Q_OS_WIN
1682 case QEvent::LocaleChange: {
1683 // on Windows the event propagation is taken care by the
1684 // WM_SETTINGCHANGE event handler.
1686 for (auto *w : list) {
1687 if (!(w->windowType() == Qt::Desktop)) {
1688 if (!w->testAttribute(Qt::WA_SetLocale))
1689 w->d_func()->setLocale_helper(QLocale(), true);
1690 }
1691 }
1692 break;
1693 }
1694#endif
1695 case QEvent::Timer: {
1696 QTimerEvent *te = static_cast<QTimerEvent*>(e);
1697 Q_ASSERT(te != nullptr);
1698 if (te->timerId() == d->toolTipWakeUp.timerId()) {
1699 d->toolTipWakeUp.stop();
1700 if (d->toolTipWidget) {
1701 QWidget *w = d->toolTipWidget->window();
1702 // show tooltip if WA_AlwaysShowToolTips is set, or if
1703 // any ancestor of d->toolTipWidget is the active
1704 // window
1705 bool showToolTip = w->testAttribute(Qt::WA_AlwaysShowToolTips);
1706 while (w && !showToolTip) {
1707 showToolTip = w->isActiveWindow();
1708 w = w->parentWidget();
1709 w = w ? w->window() : nullptr;
1710 }
1711 if (showToolTip) {
1712 QHelpEvent e(QEvent::ToolTip, d->toolTipPos, d->toolTipGlobalPos);
1713 QCoreApplication::sendEvent(d->toolTipWidget, &e);
1714 if (e.isAccepted()) {
1715 QStyle *s = d->toolTipWidget->style();
1716 int sleepDelay = s->styleHint(QStyle::SH_ToolTip_FallAsleepDelay, nullptr, d->toolTipWidget, nullptr);
1717 d->toolTipFallAsleep.start(sleepDelay, this);
1718 }
1719 }
1720 }
1721 } else if (te->timerId() == d->toolTipFallAsleep.timerId()) {
1722 d->toolTipFallAsleep.stop();
1723 }
1724 break;
1725 }
1726#if QT_CONFIG(whatsthis)
1729 return true;
1730#endif
1734 // QGuiApplication::event does not account for the cases where
1735 // there is a top level widget without a window handle. So they
1736 // need to have the event posted here
1738 for (auto *w : list) {
1739 if (!w->windowHandle() && (w->windowType() != Qt::Desktop))
1740 postEvent(w, new QEvent(e->type()));
1741 }
1742 break;
1743 }
1744 default:
1745 break;
1746 }
1747
1748 return QGuiApplication::event(e);
1749}
1750
1751// ### FIXME: topLevelWindows does not contain QWidgets without a parent
1752// until QWidgetPrivate::create is called. So we have to override the
1753// QGuiApplication::notifyLayoutDirectionChange
1754// to do the right thing.
1756{
1759
1760 // send to all top-level QWidgets
1761 for (auto *w : list) {
1762 windowList.removeAll(w->windowHandle());
1765 }
1766
1767 // in case there are any plain QWindows in this QApplication-using
1768 // application, also send the notification to them
1769 for (int i = 0; i < windowList.size(); ++i) {
1771 QCoreApplication::sendEvent(windowList.at(i), &ev);
1772 }
1773}
1774
1794#if QT_DEPRECATED_SINCE(6,5)
1795void QApplication::setActiveWindow(QWidget* act)
1796{
1798}
1799#endif
1800
1802{
1803 QWidget* window = act?act->window():nullptr;
1804
1806 return;
1807
1808#if QT_CONFIG(graphicsview)
1809 if (window && window->graphicsProxyWidget()) {
1810 // Activate the proxy's view->viewport() ?
1811 return;
1812 }
1813#endif
1814
1815 QWidgetList toBeActivated;
1816 QWidgetList toBeDeactivated;
1817
1821 for (auto *w : list) {
1822 if (w->isVisible() && w->isActiveWindow())
1823 toBeDeactivated.append(w);
1824 }
1825 } else {
1827 }
1828 }
1829
1833
1836 }
1837
1839
1843 for (auto *w : list) {
1844 if (w->isVisible() && w->isActiveWindow())
1845 toBeActivated.append(w);
1846 }
1847 } else {
1849 }
1850
1851 }
1852
1853 // first the activation/deactivation events
1854 QEvent activationChange(QEvent::ActivationChange);
1855 QEvent windowActivate(QEvent::WindowActivate);
1856 QEvent windowDeactivate(QEvent::WindowDeactivate);
1857
1858 for (int i = 0; i < toBeActivated.size(); ++i) {
1859 QWidget *w = toBeActivated.at(i);
1860 QApplication::sendSpontaneousEvent(w, &windowActivate);
1861 QApplication::sendSpontaneousEvent(w, &activationChange);
1862 }
1863
1864 for(int i = 0; i < toBeDeactivated.size(); ++i) {
1865 QWidget *w = toBeDeactivated.at(i);
1866 QApplication::sendSpontaneousEvent(w, &windowDeactivate);
1867 QApplication::sendSpontaneousEvent(w, &activationChange);
1868 }
1869
1870 if (QApplicationPrivate::popupWidgets == nullptr) { // !inPopupMode()
1871 // then focus events
1876 if (w && w->isVisible() /*&& w->focusPolicy() != QWidget::NoFocus*/)
1878 else {
1880 if (w) {
1881 w->setFocus(Qt::ActiveWindowFocusReason);
1882 } else {
1884 if (!w && QApplicationPrivate::active_window->focusPolicy() != Qt::NoFocus) {
1886 } else if (!QApplicationPrivate::active_window->isAncestorOf(w)) {
1887 // If the focus widget is not in the activate_window, clear the focus
1889 }
1890 }
1891 }
1892 }
1893 }
1894}
1895
1897{
1898 // QTBUG-32177, wnd might be a QQuickView embedded via window container.
1899 while (wnd && !wnd->isTopLevel()) {
1900 QWindow *parent = wnd->parent();
1901 if (!parent)
1902 break;
1903
1904 // Don't end up in windows not belonging to this application
1905 if (parent->handle() && parent->handle()->isForeignWindow())
1906 break;
1907
1908 wnd = wnd->parent();
1909 }
1910 if (wnd) {
1911 const auto tlws = QApplication::topLevelWidgets();
1912 for (QWidget *tlw : tlws) {
1913 if (tlw->windowHandle() == wnd)
1914 return tlw;
1915 }
1916 }
1917 return nullptr;
1918}
1919
1921{
1922#ifndef Q_OS_MACOS
1923 // Some delayed focus event to ignore, unless we are on cocoa where
1924 // popups can be opened via right-click on inactive applications
1925 if (inPopupMode())
1926 return;
1927#endif
1929 QWidget *focusWidget = qt_tlw_for_window(focusWindow);
1931 // QTBUG-37126, Active X controls may set the focus on native child widgets.
1932 if (focusWindow && focusWidget && focusWindow != focusWidget->windowHandle()) {
1933 if (QWidgetWindow *widgetWindow = qobject_cast<QWidgetWindow *>(focusWindow))
1934 if (QWidget *widget = widgetWindow->widget())
1935 if (widget->inherits("QAxHostWidget"))
1937 }
1938
1939 // QApplication::setActiveWindow() will deliver window activation events for
1940 // QWidgetWindows. But for other subclasses of QWindow (like QQuickWindow), we
1941 // need to send them explicitly, like we do from the base class implementation.
1942 if (previous && !qobject_cast<QWidgetWindow *>(previous)) {
1944 QCoreApplication::sendEvent(previous, &de);
1945 }
1946
1947 if (focusWindow && !qobject_cast<QWidgetWindow *>(focusWindow)) {
1949 QCoreApplication::sendEvent(focusWindow, &ae);
1950 }
1951
1952 // don't call base class to avoid double delivery of WindowActivate/Deactivate events
1953}
1954
1961 bool *wrappingOccurred)
1962{
1964
1965 QWidget *f = toplevel->focusWidget();
1966 if (!f)
1967 f = toplevel;
1968
1969 QWidget *w = f;
1970 QWidget *test = f->d_func()->focus_next;
1971 bool seenWindow = false;
1972 bool focusWidgetAfterWindow = false;
1973 while (test && test != f) {
1974 if (test->isWindow())
1975 seenWindow = true;
1976
1977 // If the next focus widget has a focus proxy, we need to check to ensure
1978 // that the proxy is in the correct parent-child direction (according to
1979 // \a next). This is to ensure that we can tab in and out of compound widgets
1980 // without getting stuck in a tab-loop between parent and child.
1981 QWidget *focusProxy = test->d_func()->deepestFocusProxy();
1982 auto effectiveFocusPolicy = [](QWidget *widget) {
1984 };
1985 const bool canTakeFocus = (effectiveFocusPolicy(focusProxy ? focusProxy : test)
1986 & focus_flag) == focus_flag;
1987 const bool composites = focusProxy ? (next ? focusProxy->isAncestorOf(test)
1988 : test->isAncestorOf(focusProxy))
1989 : false;
1990 if (canTakeFocus && !composites
1991 && test->isVisibleTo(toplevel) && test->isEnabled()
1992 && !(w->windowType() == Qt::SubWindow && !w->isAncestorOf(test))
1993 && (toplevel->windowType() != Qt::SubWindow || toplevel->isAncestorOf(test))
1994 && f != focusProxy) {
1995 w = test;
1996 if (seenWindow)
1997 focusWidgetAfterWindow = true;
1998 if (next)
1999 break;
2000 }
2001 test = test->d_func()->focus_next;
2002 }
2003
2004 if (wrappingOccurred != nullptr)
2005 *wrappingOccurred = next ? focusWidgetAfterWindow : !focusWidgetAfterWindow;
2006
2007 if (w == f) {
2008 if (qt_in_tab_key_event) {
2009 w->window()->setAttribute(Qt::WA_KeyboardFocusChange);
2010 w->update();
2011 }
2012 return nullptr;
2013 }
2014 return w;
2015}
2016
2025{
2026#if 0
2027 if (leave) {
2030 }
2031 if (enter) {
2032 const QPoint windowPos = enter->window()->mapFromGlobal(globalPos);
2033 QEnterEvent e(enter->mapFromGlobal(globalPos), windowPos, globalPos);
2035 }
2036 return;
2037#endif
2038
2039 if ((!enter && !leave) || (enter == leave))
2040 return;
2041
2042 QWidgetList leaveList;
2043 QWidgetList enterList;
2044
2045 bool sameWindow = leave && enter && leave->window() == enter->window();
2046 if (leave && !sameWindow) {
2047 auto *w = leave;
2048 do {
2049 leaveList.append(w);
2050 } while (!w->isWindow() && (w = w->parentWidget()));
2051 }
2052 if (enter && !sameWindow) {
2053 auto *w = enter;
2054 do {
2055 enterList.append(w);
2056 } while (!w->isWindow() && (w = w->parentWidget()));
2057 }
2058 if (sameWindow) {
2059 int enterDepth = 0;
2060 int leaveDepth = 0;
2061 auto *e = enter;
2062 while (!e->isWindow() && (e = e->parentWidget()))
2063 enterDepth++;
2064 auto *l = leave;
2065 while (!l->isWindow() && (l = l->parentWidget()))
2066 leaveDepth++;
2067 QWidget* wenter = enter;
2068 QWidget* wleave = leave;
2069 while (enterDepth > leaveDepth) {
2070 wenter = wenter->parentWidget();
2071 enterDepth--;
2072 }
2073 while (leaveDepth > enterDepth) {
2074 wleave = wleave->parentWidget();
2075 leaveDepth--;
2076 }
2077 while (!wenter->isWindow() && wenter != wleave) {
2078 wenter = wenter->parentWidget();
2079 wleave = wleave->parentWidget();
2080 }
2081
2082 for (auto *w = leave; w != wleave; w = w->parentWidget())
2083 leaveList.append(w);
2084
2085 for (auto *w = enter; w != wenter; w = w->parentWidget())
2086 enterList.append(w);
2087 }
2088
2089 QEvent leaveEvent(QEvent::Leave);
2090 for (int i = 0; i < leaveList.size(); ++i) {
2091 auto *w = leaveList.at(i);
2093 QCoreApplication::sendEvent(w, &leaveEvent);
2094 if (w->testAttribute(Qt::WA_Hover) &&
2096 Q_ASSERT(instance());
2097 QHoverEvent he(QEvent::HoverLeave, QPointF(-1, -1), globalPosF, w->mapFromGlobal(globalPosF),
2099 qApp->d_func()->notify_helper(w, &he);
2100 }
2101 }
2102 }
2103 if (!enterList.isEmpty()) {
2104 // Guard against QGuiApplicationPrivate::lastCursorPosition initialized to qInf(), qInf().
2105 const QPointF globalPos = qIsInf(globalPosF.x())
2107 : globalPosF;
2108 const QPointF windowPos = std::as_const(enterList).back()->window()->mapFromGlobal(globalPos);
2109 for (auto it = enterList.crbegin(), end = enterList.crend(); it != end; ++it) {
2110 auto *w = *it;
2112 const QPointF localPos = w->mapFromGlobal(globalPos);
2113 QEnterEvent enterEvent(localPos, windowPos, globalPos);
2114 QCoreApplication::sendEvent(w, &enterEvent);
2115 if (w->testAttribute(Qt::WA_Hover) &&
2117 QHoverEvent he(QEvent::HoverEnter, windowPos, QPointF(-1, -1), globalPos,
2119 QMutableEventPoint::setPosition(he.point(0), localPos);
2120 qApp->d_func()->notify_helper(w, &he);
2121 }
2122 }
2123 }
2124 }
2125
2126#ifndef QT_NO_CURSOR
2127 // Update cursor for alien/graphics widgets.
2128
2129 const bool enterOnAlien = (enter && (isAlien(enter) || enter->testAttribute(Qt::WA_DontShowOnScreen)));
2130 // Whenever we leave an alien widget on X11/QPA, we need to reset its nativeParentWidget()'s cursor.
2131 // This is not required on Windows as the cursor is reset on every single mouse move.
2132 QWidget *parentOfLeavingCursor = nullptr;
2133 for (int i = 0; i < leaveList.size(); ++i) {
2134 auto *w = leaveList.at(i);
2135 if (!isAlien(w))
2136 break;
2137 if (w->testAttribute(Qt::WA_SetCursor)) {
2138 QWidget *parent = w->parentWidget();
2139 while (parent && parent->d_func()->data.in_destructor)
2140 parent = parent->parentWidget();
2141 parentOfLeavingCursor = parent;
2142 //continue looping, we need to find the downest alien widget with a cursor.
2143 // (downest on the screen)
2144 }
2145 }
2146 //check that we will not call qt_x11_enforce_cursor twice with the same native widget
2147 if (parentOfLeavingCursor && (!enterOnAlien
2148 || parentOfLeavingCursor->effectiveWinId() != enter->effectiveWinId())) {
2149#if QT_CONFIG(graphicsview)
2150 if (!parentOfLeavingCursor->window()->graphicsProxyWidget())
2151#endif
2152 {
2153 if (enter == QApplicationPrivate::desktop()) {
2154 qt_qpa_set_cursor(enter, true);
2155 } else {
2156 qt_qpa_set_cursor(parentOfLeavingCursor, true);
2157 }
2158 }
2159 }
2160 if (enterOnAlien) {
2161 QWidget *cursorWidget = enter;
2162 while (!cursorWidget->isWindow() && !cursorWidget->isEnabled())
2163 cursorWidget = cursorWidget->parentWidget();
2164
2165 if (!cursorWidget)
2166 return;
2167
2168#if QT_CONFIG(graphicsview)
2169 if (cursorWidget->window()->graphicsProxyWidget()) {
2170 QWidgetPrivate::nearestGraphicsProxyWidget(cursorWidget)->setCursor(cursorWidget->cursor());
2171 } else
2172#endif
2173 {
2174 qt_qpa_set_cursor(cursorWidget, true);
2175 }
2176 }
2177#endif
2178}
2179
2180/* exported for the benefit of testing tools */
2181Q_WIDGETS_EXPORT bool qt_tryModalHelper(QWidget *widget, QWidget **rettop)
2182{
2184}
2185
2190{
2191 widget = widget->window();
2193 return window && self->isWindowBlocked(window);
2194}
2195
2197{
2198 return Qt::ApplicationModal;
2199}
2200
2202{
2204 QWindow *popupWindow = popupWidget ? popupWidget->windowHandle() : nullptr;
2205 return popupWindow == window || (!popupWindow && QWindowPrivate::get(window)->isPopup());
2206}
2207
2214{
2216 if (rettop)
2217 *rettop = top;
2218
2219 // the active popup widget always gets the input event
2221 return true;
2222
2223 return !isBlockedByModal(widget->window());
2224}
2225
2227{
2228 QWidget * top = nullptr;
2229
2231 return true;
2232
2233 bool block_event = false;
2234
2235 switch (type) {
2236 case QEvent::MouseButtonPress: // disallow mouse/key events
2238 case QEvent::MouseMove:
2239 case QEvent::KeyPress:
2240 case QEvent::KeyRelease:
2241 block_event = true;
2242 break;
2243 default:
2244 break;
2245 }
2246
2247 if (block_event && top && top->parentWidget() == nullptr)
2248 top->raise();
2249
2250 return !block_event;
2251}
2252
2254{
2255 return !self->modalWindowList.isEmpty();
2256}
2257
2258/*
2259 \internal
2260*/
2263 Qt::MouseButtons buttons, QWidget *buttonDown,
2264 QWidget *alienWidget)
2265{
2266 Q_ASSERT(candidate);
2267
2268 QWidget *mouseGrabber = QWidget::mouseGrabber();
2269 if (((type == QEvent::MouseMove && buttons) || (type == QEvent::MouseButtonRelease))
2270 && !buttonDown && !mouseGrabber) {
2271 return nullptr;
2272 }
2273
2274 if (alienWidget && alienWidget->internalWinId())
2275 alienWidget = nullptr;
2276
2277 QWidget *receiver = candidate;
2278
2279 if (!mouseGrabber)
2280 mouseGrabber = (buttonDown && !isBlockedByModal(buttonDown)) ? buttonDown : alienWidget;
2281
2282 if (mouseGrabber && mouseGrabber != candidate) {
2283 receiver = mouseGrabber;
2284 *pos = receiver->mapFromGlobal(candidate->mapToGlobal(windowPos));
2285 }
2286
2287 return receiver;
2288
2289}
2290
2291/*
2292 \internal
2293*/
2295 QWidget *alienWidget, QWidget *nativeWidget,
2296 QWidget **buttonDown, QPointer<QWidget> &lastMouseReceiver,
2297 bool spontaneous, bool onlyDispatchEnterLeave)
2298{
2299 Q_ASSERT(receiver);
2300 Q_ASSERT(event);
2301 Q_ASSERT(nativeWidget);
2302 Q_ASSERT(buttonDown);
2303
2304 if (alienWidget && !isAlien(alienWidget))
2305 alienWidget = nullptr;
2306
2307 QPointer<QWidget> receiverGuard = receiver;
2308 QPointer<QWidget> nativeGuard = nativeWidget;
2309 QPointer<QWidget> alienGuard = alienWidget;
2311
2312 const bool graphicsWidget = nativeWidget->testAttribute(Qt::WA_DontShowOnScreen);
2313
2314 bool widgetUnderMouse = QRectF(receiver->rect()).contains(event->position());
2315
2316 // Clear the obsolete leaveAfterRelease value, if mouse button has been released but
2317 // leaveAfterRelease has not been updated.
2318 // This happens e.g. when modal dialog or popup is shown as a response to button click.
2319 if (leaveAfterRelease && !*buttonDown && !event->buttons())
2320 leaveAfterRelease = nullptr;
2321
2322 if (*buttonDown) {
2323 if (!graphicsWidget) {
2324 // Register the widget that shall receive a leave event
2325 // after the last button is released.
2326 if ((alienWidget || !receiver->internalWinId()) && !leaveAfterRelease && !QWidget::mouseGrabber())
2327 leaveAfterRelease = *buttonDown;
2328 if (event->type() == QEvent::MouseButtonRelease && !event->buttons())
2329 *buttonDown = nullptr;
2330 }
2331 } else if (lastMouseReceiver && widgetUnderMouse) {
2332 // Dispatch enter/leave if we move:
2333 // 1) from an alien widget to another alien widget or
2334 // from a native widget to an alien widget (first OR case)
2335 // 2) from an alien widget to a native widget (second OR case)
2336 if ((alienWidget && alienWidget != lastMouseReceiver)
2337 || (isAlien(lastMouseReceiver) && !alienWidget)) {
2338 if (activePopupWidget) {
2339 if (!QWidget::mouseGrabber())
2340 dispatchEnterLeave(alienWidget ? alienWidget : nativeWidget, lastMouseReceiver, event->globalPosition());
2341 } else {
2342 dispatchEnterLeave(receiver, lastMouseReceiver, event->globalPosition());
2343 }
2344
2345 }
2346 }
2347
2348 // We need this quard in case someone opens a modal dialog / popup. If that's the case
2349 // leaveAfterRelease is set to null, but we shall not update lastMouseReceiver.
2350 const bool wasLeaveAfterRelease = leaveAfterRelease != nullptr;
2351 bool result = true;
2352 // This code is used for sending the synthetic enter/leave events for cases where it is needed
2353 // due to other events causing the widget under the mouse to change. However in those cases
2354 // we do not want to send the mouse event associated with this call, so this enables us to
2355 // not send the unneeded mouse event
2356 if (!onlyDispatchEnterLeave) {
2357 if (spontaneous)
2358 result = QApplication::sendSpontaneousEvent(receiver, event);
2359 else
2361 }
2362
2363 if (!graphicsWidget && leaveAfterRelease && event->type() == QEvent::MouseButtonRelease
2364 && !event->buttons() && QWidget::mouseGrabber() != leaveAfterRelease) {
2365 // Dispatch enter/leave if:
2366 // 1) the mouse grabber is an alien widget
2367 // 2) the button is released on an alien widget
2368 QWidget *enter = nullptr;
2369 if (nativeGuard)
2370 enter = alienGuard ? alienWidget : nativeWidget;
2371 else // The receiver is typically deleted on mouse release with drag'n'drop.
2372 enter = QApplication::widgetAt(event->globalPosition().toPoint());
2373 dispatchEnterLeave(enter, leaveAfterRelease, event->globalPosition());
2374 leaveAfterRelease = nullptr;
2375 lastMouseReceiver = enter;
2376 } else if (!wasLeaveAfterRelease) {
2377 if (activePopupWidget) {
2378 if (!QWidget::mouseGrabber())
2379 lastMouseReceiver = alienGuard ? alienWidget : (nativeGuard ? nativeWidget : nullptr);
2380 } else {
2381 lastMouseReceiver = receiverGuard ? receiver : QApplication::widgetAt(event->globalPosition().toPoint());
2382 }
2383 }
2384
2385 return result;
2386}
2387
2388/*
2389 This function should only be called when the widget changes visibility, i.e.
2390 when the \a widget is shown, hidden or deleted. This function does nothing
2391 if the widget is a top-level or native, i.e. not an alien widget. In that
2392 case enter/leave events are generated by the underlying windowing system.
2393*/
2395extern Q_WIDGETS_EXPORT QWidget *qt_button_down;
2397{
2398#ifndef QT_NO_CURSOR
2399 if (!widget || widget->isWindow())
2400 return;
2401 const bool widgetInShow = widget->isVisible() && !widget->data->in_destructor;
2402 if (!widgetInShow && widget != qt_last_mouse_receiver)
2403 return; // Widget was not under the cursor when it was hidden/deleted.
2404
2405 if (widgetInShow && widget->parentWidget()->data->in_show)
2406 return; // Ignore recursive show.
2407
2408 QWidget *mouseGrabber = QWidget::mouseGrabber();
2409 if (mouseGrabber && mouseGrabber != widget)
2410 return; // Someone else has the grab; enter/leave should not occur.
2411
2412 QWidget *tlw = widget->window();
2413 if (tlw->data->in_destructor || tlw->data->is_closing)
2414 return; // Closing down the business.
2415
2416 if (widgetInShow && (!qt_last_mouse_receiver || qt_last_mouse_receiver->window() != tlw))
2417 return; // Mouse cursor not inside the widget's top-level.
2418
2419 const QPoint globalPos(QCursor::pos());
2420 QPoint windowPos = tlw->mapFromGlobal(globalPos);
2421
2422 // Find the current widget under the mouse. If this function was called from
2423 // the widget's destructor, we have to make sure childAt() doesn't take into
2424 // account widgets that are about to be destructed.
2425 QWidget *widgetUnderCursor = tlw->d_func()->childAt_helper(windowPos, widget->data->in_destructor);
2426 if (!widgetUnderCursor)
2427 widgetUnderCursor = tlw;
2428 QPoint pos = widgetUnderCursor->mapFrom(tlw, windowPos);
2429
2430 if (widgetInShow && widgetUnderCursor != widget && !widget->isAncestorOf(widgetUnderCursor))
2431 return; // Mouse cursor not inside the widget or any of its children.
2432
2433 if (widget->data->in_destructor && qt_button_down == widget)
2434 qt_button_down = nullptr;
2435
2436 // A mouse move is not actually sent, but we utilize the sendMouseEvent() call to send the
2437 // enter/leave events as appropriate
2439 sendMouseEvent(widgetUnderCursor, &e, widgetUnderCursor, tlw, &qt_button_down, qt_last_mouse_receiver, true, true);
2440#else // !QT_NO_CURSOR
2442#endif // QT_NO_CURSOR
2443}
2444
2454{
2455 CHECK_QAPP_INSTANCE(nullptr)
2456 if (!qt_desktopWidget || // not created yet
2457 !(qt_desktopWidget->windowType() == Qt::Desktop)) { // reparented away
2458 qt_desktopWidget = new QWidget(nullptr, Qt::Desktop);
2459 }
2460 return qt_desktopWidget;
2461}
2462
2463/*
2464 Sets the time after which a drag should start to \a ms ms.
2465
2466 \sa startDragTime()
2467*/
2468
2470{
2472}
2473
2492{
2494}
2495
2496/*
2497 Sets the distance after which a drag should start to \a l pixels.
2498
2499 \sa startDragDistance()
2500*/
2501
2503{
2505}
2506
2531{
2533}
2534
2565{
2566 return QGuiApplication::exec();
2567}
2568
2572{
2573 Q_D(QApplication);
2574 // no events are delivered after ~QCoreApplication() has started
2576 return true;
2577
2578 if (Q_UNLIKELY(!receiver)) { // serious error
2579 qWarning("QApplication::notify: Unexpected null receiver");
2580 return true;
2581 }
2582
2583#ifndef QT_NO_DEBUG
2585#endif
2586
2587 const bool isWindowType = receiver->isWindowType();
2588 const bool isWidgetType = receiver->isWidgetType();
2589 if (isWindowType
2591 return true; // Platform plugin ate the event
2592 }
2593
2595
2596#ifndef QT_NO_GESTURES
2597 // walk through parents and check for gestures
2598 if (d->gestureManager) {
2599 switch (e->type()) {
2600 case QEvent::Paint:
2601 case QEvent::MetaCall:
2610 case QEvent::Style:
2611 case QEvent::IconDrag:
2619 break;
2620 default:
2621 if (d->gestureManager->thread() == QThread::currentThread()) {
2622 if (isWidgetType) {
2623 if (d->gestureManager->filterEvent(static_cast<QWidget *>(receiver), e))
2624 return true;
2625 } else {
2626 // a special case for events that go to QGesture objects.
2627 // We pass the object to the gesture manager and it'll figure
2628 // out if it's QGesture or not.
2629 if (d->gestureManager->filterEvent(receiver, e))
2630 return true;
2631 }
2632 }
2633 break;
2634 }
2635 }
2636#endif // QT_NO_GESTURES
2637
2638 switch (e->type()) {
2641 // Close all popups (triggers when switching applications
2642 // by pressing ALT-TAB on Windows, which is not receive as key event.
2643 // triggers when the screen rotates.)
2644 d->closeAllPopups();
2645 break;
2646 case QEvent::Wheel: // User input and window activation makes tooltips sleep
2648 case QEvent::KeyPress:
2649 case QEvent::KeyRelease:
2650 case QEvent::FocusOut:
2651 case QEvent::FocusIn:
2655 d->toolTipFallAsleep.stop();
2656 Q_FALLTHROUGH();
2657 case QEvent::Leave:
2658 d->toolTipWakeUp.stop();
2659 default:
2660 break;
2661 }
2662
2663 switch (e->type()) {
2664 case QEvent::KeyPress: {
2665 QKeyEvent* keyEvent = static_cast<QKeyEvent*>(e);
2666 const int key = keyEvent->key();
2667 // When a key press is received which is not spontaneous then it needs to
2668 // be manually sent as a shortcut override event to ensure that any
2669 // matching shortcut is triggered first. This enables emulation/playback
2670 // of recorded events to still have the same effect.
2671 if (!e->spontaneous() && isWidgetType
2672 && qt_sendShortcutOverrideEvent(static_cast<QWidget *>(receiver), keyEvent->timestamp(),
2673 key, keyEvent->modifiers(), keyEvent->text(),
2674 keyEvent->isAutoRepeat(), keyEvent->count())) {
2675 return true;
2676 }
2678 || key == Qt::Key_Tab
2679 || key == Qt::Key_Left
2680 || key == Qt::Key_Up
2681 || key == Qt::Key_Right
2682 || key == Qt::Key_Down);
2683 }
2684 default:
2685 break;
2686 }
2687
2688 bool res = false;
2689 if (isWidgetType) {
2690 QWidget * w = static_cast<QWidget *>(receiver);
2691 switch (e->type()) {
2693 case QEvent::KeyPress:
2694 case QEvent::KeyRelease: {
2695 QKeyEvent* key = static_cast<QKeyEvent*>(e);
2696 bool def = key->isAccepted();
2697 /*
2698 QLineEdit will emit a signal on Key_Return, but
2699 ignore the event, and sometimes the connected
2700 slot deletes the QLineEdit (common in itemview
2701 delegates), so we have to check if the widget
2702 was destroyed even if the event was ignored (to
2703 prevent a crash)
2704
2705 Note that we don't have to reset pr while
2706 propagating (because the original receiver will
2707 be destroyed if one of its ancestors is)
2708 */
2709 QPointer<QObject> pr = receiver;
2710 while (w) {
2711 if (def)
2712 key->accept();
2713 else
2714 key->ignore();
2715 res = d->notify_helper(w, e);
2716
2717 if (res && key->isAccepted())
2718 break;
2719 if (!pr || w->isWindow())
2720 break;
2721
2722 w = w->parentWidget();
2723 }
2724 qt_in_tab_key_event = false;
2725 break;
2726 }
2730 case QEvent::MouseMove: {
2731 QMouseEvent* mouse = static_cast<QMouseEvent*>(e);
2732 QPoint relpos = mouse->position().toPoint();
2733
2734 if (e->spontaneous()) {
2735 if (e->type() != QEvent::MouseMove)
2736 QApplicationPrivate::giveFocusAccordingToFocusPolicy(w, e, relpos);
2737
2738 // ### Qt 7 These dynamic tool tips should be an OPT-IN feature. Some platforms
2739 // like macOS (probably others too), can optimize their views by not
2740 // dispatching mouse move events. We have attributes to control hover,
2741 // and mouse tracking, but as long as we are deciding to implement this
2742 // feature without choice of opting-in or out, you ALWAYS have to have
2743 // tracking enabled. Therefore, the other properties give a false sense of
2744 // performance enhancement.
2745 if (e->type() == QEvent::MouseMove && mouse->buttons() == 0
2746 && w->rect().contains(relpos)) { // Outside due to mouse grab?
2747 d->toolTipWidget = w;
2748 d->toolTipPos = relpos;
2749 d->toolTipGlobalPos = mouse->globalPosition().toPoint();
2750 QStyle *s = d->toolTipWidget->style();
2751 int wakeDelay = s->styleHint(QStyle::SH_ToolTip_WakeUpDelay, nullptr, d->toolTipWidget, nullptr);
2752 d->toolTipWakeUp.start(d->toolTipFallAsleep.isActive() ? 20 : wakeDelay, this);
2753 }
2754 }
2755
2756 bool eventAccepted = mouse->isAccepted();
2757
2758 QPointer<QWidget> pw = w;
2759 while (w) {
2760 QMouseEvent me(mouse->type(), relpos, mouse->scenePosition(), mouse->globalPosition().toPoint(),
2761 mouse->button(), mouse->buttons(), mouse->modifiers(), mouse->source(),
2762 mouse->pointingDevice());
2763 me.m_spont = mouse->spontaneous();
2764 me.setTimestamp(mouse->timestamp());
2766 // throw away any mouse-tracking-only mouse events
2767 if (!w->hasMouseTracking()
2768 && mouse->type() == QEvent::MouseMove && mouse->buttons() == 0) {
2769 // but still send them through all application event filters (normally done by notify_helper)
2770 d->sendThroughApplicationEventFilters(w, w == receiver ? mouse : &me);
2771 res = true;
2772 } else {
2773 w->setAttribute(Qt::WA_NoMouseReplay, false);
2774 res = d->notify_helper(w, w == receiver ? mouse : &me);
2775 e->m_spont = false;
2776 }
2777 eventAccepted = (w == receiver ? mouse : &me)->isAccepted();
2778 if (res && eventAccepted)
2779 break;
2780 if (w->isWindow() || w->testAttribute(Qt::WA_NoMousePropagation))
2781 break;
2782 relpos += w->pos();
2783 w = w->parentWidget();
2784 }
2785
2786 mouse->setAccepted(eventAccepted);
2787
2788 if (e->type() == QEvent::MouseMove) {
2789 if (!pw)
2790 break;
2791
2792 w = static_cast<QWidget *>(receiver);
2793 relpos = mouse->position().toPoint();
2794 QPoint diff = relpos - w->mapFromGlobal(mouse->globalPosition().toPoint());
2795 while (w) {
2796 if (w->testAttribute(Qt::WA_Hover) &&
2798 QHoverEvent he(QEvent::HoverMove, mouse->scenePosition(), mouse->globalPosition(), relpos - diff, mouse->modifiers());
2799 QMutableEventPoint::setPosition(he.point(0), relpos);
2800 d->notify_helper(w, &he);
2801 }
2802 if (w->isWindow() || w->testAttribute(Qt::WA_NoMousePropagation))
2803 break;
2804 relpos += w->pos();
2805 w = w->parentWidget();
2806 }
2807 }
2808
2809 d->hoverGlobalPos = mouse->globalPosition().toPoint();
2810 break;
2811 }
2812#if QT_CONFIG(wheelevent)
2813 case QEvent::Wheel: {
2814 // QTBUG-40656, QTBUG-42731: ignore wheel events when a popup (QComboBox) is open.
2815 if (const QWidget *popup = QApplication::activePopupWidget()) {
2816 if (w->window() != popup)
2817 return true;
2818 }
2819
2820 QWheelEvent* wheel = static_cast<QWheelEvent*>(e);
2821 if (!wheel->spontaneous()) {
2822 /*
2823 Synthesized events shouldn't propagate, e.g. QScrollArea passes events from the
2824 viewport on to the scrollbars, which might ignore the event if there is no more
2825 space to scroll. If we would propagate, the event would come back to the viewport.
2826 */
2827 res = d->notify_helper(w, wheel);
2828 break;
2829 }
2830
2831 const Qt::ScrollPhase phase = wheel->phase();
2832 QPoint relpos = wheel->position().toPoint();
2833
2834 // Ideally, we should lock on a widget when it starts receiving wheel
2835 // events. This avoids other widgets to start receiving those events
2836 // as the mouse cursor hovers them. However, given the way common
2837 // wheeled mice work, there's no certain way of connecting different
2838 // wheel events as a stream. This results in the NoScrollPhase case,
2839 // where we just send the event from the original receiver and up its
2840 // hierarchy until the event gets accepted.
2841 //
2842 // In the case of more evolved input devices, like Apple's trackpad or
2843 // Magic Mouse, we receive the scroll phase information. This helps us
2844 // connect wheel events as a stream and therefore makes it easier to
2845 // lock on the widget onto which the scrolling was initiated.
2846 //
2847 // We assume that, when supported, the phase cycle follows the pattern:
2848 //
2849 // ScrollBegin (ScrollUpdate* ScrollMomentum* ScrollEnd)+
2850 //
2851 // This means that we can have scrolling sequences (starting with ScrollBegin)
2852 // or partial sequences (after a ScrollEnd and starting with ScrollUpdate).
2853
2854 // a widget has already grabbed the wheel for a sequence
2855 if (QApplicationPrivate::wheel_widget) {
2856 Q_ASSERT(phase != Qt::NoScrollPhase);
2857 w = QApplicationPrivate::wheel_widget;
2858 relpos = w->mapFromGlobal(wheel->globalPosition().toPoint());
2859 }
2860 /*
2861 Start or finish a scrolling sequence by grabbing/releasing the wheel via
2862 wheel_widget. The sequence might be partial (ie. not start with ScrollBegin),
2863 e.g. if the previous wheel_widget was destroyed mid-sequence.
2864 */
2865 switch (phase) {
2866 case Qt::ScrollEnd:
2867 QApplicationPrivate::wheel_widget = nullptr;
2868 break;
2869 case Qt::ScrollBegin:
2870 QApplicationPrivate::wheel_widget = w;
2871 Q_FALLTHROUGH();
2872 case Qt::ScrollUpdate:
2873 case Qt::ScrollMomentum:
2874 if (!QApplicationPrivate::wheel_widget)
2875 QApplicationPrivate::wheel_widget = w;
2876 Q_FALLTHROUGH();
2877 case Qt::NoScrollPhase:
2878 QApplicationPrivate::giveFocusAccordingToFocusPolicy(w, e, relpos);
2879 break;
2880 // no default: - we want warnings if we don't handle all phases explicitly
2881 }
2882
2883 QWheelEvent we(relpos, wheel->globalPosition(), wheel->pixelDelta(), wheel->angleDelta(), wheel->buttons(),
2884 wheel->modifiers(), phase, wheel->inverted(), wheel->source(), wheel->pointingDevice());
2885
2886 we.setTimestamp(wheel->timestamp());
2887 bool eventAccepted;
2888 do {
2889 // events are delivered as accepted and ignored by the default event handler
2890 // since we always send the same QWheelEvent object, we need to reset the accepted state
2891 we.setAccepted(true);
2892 we.m_spont = wheel->spontaneous() && w == receiver;
2893 res = d->notify_helper(w, &we);
2894 eventAccepted = we.isAccepted();
2895 if (res && eventAccepted)
2896 break;
2897 if (w->isWindow() || w->testAttribute(Qt::WA_NoMousePropagation))
2898 break;
2899
2900 QMutableEventPoint::setPosition(we.point(0), we.position() + w->pos());
2901 w = w->parentWidget();
2902 } while (w);
2903 wheel->setAccepted(eventAccepted);
2904 break;
2905 }
2906#endif
2907#ifndef QT_NO_CONTEXTMENU
2908 case QEvent::ContextMenu: {
2909 QContextMenuEvent *context = static_cast<QContextMenuEvent*>(e);
2910 QPoint relpos = context->pos();
2911 bool eventAccepted = context->isAccepted();
2912 while (w) {
2913 QContextMenuEvent ce(context->reason(), relpos, context->globalPos(), context->modifiers());
2914 ce.m_spont = e->spontaneous();
2915 res = d->notify_helper(w, w == receiver ? context : &ce);
2916 eventAccepted = ((w == receiver) ? context : &ce)->isAccepted();
2917 e->m_spont = false;
2918
2919 if (res && eventAccepted)
2920 break;
2921 if (w->isWindow() || w->testAttribute(Qt::WA_NoMousePropagation))
2922 break;
2923
2924 relpos += w->pos();
2925 w = w->parentWidget();
2926 }
2927 context->setAccepted(eventAccepted);
2928 break;
2929 }
2930#endif // QT_NO_CONTEXTMENU
2931#if QT_CONFIG(tabletevent)
2932 case QEvent::TabletMove:
2934 case QEvent::TabletRelease: {
2935 QTabletEvent *tablet = static_cast<QTabletEvent*>(e);
2936 QPointF relpos = tablet->position();
2937 bool eventAccepted = tablet->isAccepted();
2938 while (w) {
2939 QTabletEvent te(tablet->type(), tablet->pointingDevice(), relpos, tablet->globalPosition(),
2940 tablet->pressure(), tablet->xTilt(), tablet->yTilt(),
2941 tablet->tangentialPressure(), tablet->rotation(), tablet->z(),
2942 tablet->modifiers(), tablet->button(), tablet->buttons());
2943 te.m_spont = e->spontaneous();
2944 te.setAccepted(false);
2945 res = d->notify_helper(w, w == receiver ? tablet : &te);
2946 eventAccepted = ((w == receiver) ? tablet : &te)->isAccepted();
2947 e->m_spont = false;
2948 if (res && eventAccepted)
2949 break;
2950 if (w->isWindow() || w->testAttribute(Qt::WA_NoMousePropagation))
2951 break;
2952
2953 relpos += w->pos();
2954 w = w->parentWidget();
2955 }
2956 tablet->setAccepted(eventAccepted);
2957 break;
2958 }
2959#endif // QT_CONFIG(tabletevent)
2960
2961#if QT_CONFIG(tooltip) || QT_CONFIG(whatsthis)
2962 case QEvent::ToolTip:
2963 case QEvent::WhatsThis:
2965 QHelpEvent *help = static_cast<QHelpEvent*>(e);
2966 QPoint relpos = help->pos();
2967 bool eventAccepted = help->isAccepted();
2968 while (w) {
2969 QHelpEvent he(help->type(), relpos, help->globalPos());
2970 he.m_spont = e->spontaneous();
2971 res = d->notify_helper(w, w == receiver ? help : &he);
2972 e->m_spont = false;
2973 eventAccepted = (w == receiver ? help : &he)->isAccepted();
2974 if (res && eventAccepted)
2975 break;
2976 if (w->isWindow())
2977 break;
2978
2979 relpos += w->pos();
2980 w = w->parentWidget();
2981 }
2982 help->setAccepted(eventAccepted);
2983 break;
2984 }
2985#endif
2986#if QT_CONFIG(statustip) || QT_CONFIG(whatsthis)
2987 case QEvent::StatusTip:
2989 while (w) {
2990 res = d->notify_helper(w, e);
2991 if (res && e->isAccepted())
2992 break;
2993 if (w->isWindow())
2994 break;
2995 w = w->parentWidget();
2996 }
2997 break;
2998#endif
2999
3000#if QT_CONFIG(draganddrop)
3001 case QEvent::DragEnter: {
3002 QDragEnterEvent *dragEvent = static_cast<QDragEnterEvent *>(e);
3003#if QT_CONFIG(graphicsview)
3004 // QGraphicsProxyWidget handles its own propagation,
3005 // and we must not change QDragManagers currentTarget.
3006 const auto &extra = w->window()->d_func()->extra;
3007 if (extra && extra->proxyWidget) {
3008 res = d->notify_helper(w, dragEvent);
3009 break;
3010 }
3011#endif
3012 while (w) {
3013 if (w->isEnabled() && w->acceptDrops()) {
3014 res = d->notify_helper(w, dragEvent);
3015 if (res && dragEvent->isAccepted()) {
3017 break;
3018 }
3019 }
3020 if (w->isWindow())
3021 break;
3022 dragEvent->m_pos = w->mapToParent(dragEvent->m_pos);
3023 w = w->parentWidget();
3024 }
3025 break;
3026 }
3027 case QEvent::DragMove:
3028 case QEvent::Drop:
3029 case QEvent::DragLeave: {
3030#if QT_CONFIG(graphicsview)
3031 // QGraphicsProxyWidget handles its own propagation,
3032 // and we must not change QDragManagers currentTarget.
3033 const auto &extra = w->window()->d_func()->extra;
3034 bool isProxyWidget = extra && extra->proxyWidget;
3035 if (!isProxyWidget)
3036#endif
3037 w = qobject_cast<QWidget *>(QDragManager::self()->currentTarget());
3038
3039 if (!w)
3040 break;
3041 if (e->type() == QEvent::DragMove || e->type() == QEvent::Drop) {
3042 QDropEvent *dragEvent = static_cast<QDropEvent *>(e);
3043 QWidget *origReceiver = static_cast<QWidget *>(receiver);
3044 while (origReceiver && w != origReceiver) {
3045 dragEvent->m_pos = origReceiver->mapToParent(dragEvent->m_pos);
3046 origReceiver = origReceiver->parentWidget();
3047 }
3048 }
3049 res = d->notify_helper(w, e);
3050 if (e->type() != QEvent::DragMove
3051#if QT_CONFIG(graphicsview)
3052 && !isProxyWidget
3053#endif
3054 )
3055 QDragManager::self()->setCurrentTarget(nullptr, e->type() == QEvent::Drop);
3056 break;
3057 }
3058#endif // QT_CONFIG(draganddrop)
3059 case QEvent::TouchBegin: {
3060 // Note: TouchUpdate and TouchEnd events are never propagated
3061 QMutableTouchEvent *touchEvent = QMutableTouchEvent::from(static_cast<QTouchEvent *>(e));
3062 bool eventAccepted = touchEvent->isAccepted();
3063 bool acceptTouchEvents = w->testAttribute(Qt::WA_AcceptTouchEvents);
3064
3065 if (acceptTouchEvents && e->spontaneous()
3066 && touchEvent->device()->type() != QInputDevice::DeviceType::TouchPad) {
3067 const QPoint localPos = touchEvent->points()[0].position().toPoint();
3068 QApplicationPrivate::giveFocusAccordingToFocusPolicy(w, e, localPos);
3069 }
3070
3071#ifndef QT_NO_GESTURES
3072 QPointer<QWidget> gesturePendingWidget;
3073#endif
3074
3075 while (w) {
3076 // first, try to deliver the touch event
3077 acceptTouchEvents = w->testAttribute(Qt::WA_AcceptTouchEvents);
3078 touchEvent->setTarget(w);
3079 touchEvent->setAccepted(acceptTouchEvents);
3081 res = acceptTouchEvents && d->notify_helper(w, touchEvent);
3082 eventAccepted = touchEvent->isAccepted();
3083 if (p.isNull()) {
3084 // widget was deleted
3085 w = nullptr;
3086 } else {
3087 w->setAttribute(Qt::WA_WState_AcceptedTouchBeginEvent, res && eventAccepted);
3088 }
3089 touchEvent->m_spont = false;
3090 if (res && eventAccepted) {
3091 // the first widget to accept the TouchBegin gets an implicit grab.
3092 d->activateImplicitTouchGrab(w, touchEvent);
3093 break;
3094 }
3095#ifndef QT_NO_GESTURES
3096 if (gesturePendingWidget.isNull() && w && QGestureManager::gesturePending(w))
3097 gesturePendingWidget = w;
3098#endif
3099 if (!w || w->isWindow() || w->testAttribute(Qt::WA_NoMousePropagation))
3100 break;
3101
3102 const QPoint offset = w->pos();
3103 w = w->parentWidget();
3104 touchEvent->setTarget(w);
3105 for (int i = 0; i < touchEvent->pointCount(); ++i) {
3106 auto &pt = touchEvent->point(i);
3107 QMutableEventPoint::setPosition(pt, pt.position() + offset);
3108 }
3109 }
3110
3111#ifndef QT_NO_GESTURES
3112 if (!eventAccepted && !gesturePendingWidget.isNull()) {
3113 // the first widget subscribed to a gesture gets an implicit grab for all
3114 // points, also for events and event points that have not been accepted.
3115 d->activateImplicitTouchGrab(gesturePendingWidget, touchEvent, QApplicationPrivate::GrabAllPoints);
3116 }
3117#endif
3118
3119 touchEvent->setAccepted(eventAccepted);
3120 break;
3121 }
3123 case QEvent::TouchEnd:
3124 // We may get here if the widget is subscribed to a gesture,
3125 // but has not accepted TouchBegin. Propagate touch events
3126 // only if TouchBegin has been accepted.
3127 if (w->testAttribute(Qt::WA_WState_AcceptedTouchBeginEvent))
3128 res = d->notify_helper(w, e);
3129 break;
3131 inputMethod()->show();
3132 break;
3134 inputMethod()->hide();
3135 break;
3136
3137#ifndef QT_NO_GESTURES
3139 while (w) {
3140 e->ignore();
3141 res = d->notify_helper(w, e);
3142 if (res && e->isAccepted())
3143 break;
3144 if (w->isWindow())
3145 break;
3146 w = w->parentWidget();
3147 }
3148 break;
3149 case QEvent::Gesture:
3151 QGestureEvent *gestureEvent = static_cast<QGestureEvent *>(e);
3152 QList<QGesture *> allGestures = gestureEvent->gestures();
3153
3154 bool eventAccepted = gestureEvent->isAccepted();
3155 bool wasAccepted = eventAccepted;
3156 while (w) {
3157 // send only gestures the widget expects
3158 QList<QGesture *> gestures;
3159 QWidgetPrivate *wd = w->d_func();
3160 for (int i = 0; i < allGestures.size();) {
3161 QGesture *g = allGestures.at(i);
3162 Qt::GestureType type = g->gestureType();
3165 bool deliver = contextit != wd->gestureContext.end() &&
3166 (g->state() == Qt::GestureStarted || w == receiver ||
3167 (contextit.value() & Qt::ReceivePartialGestures));
3168 if (deliver) {
3169 allGestures.removeAt(i);
3170 gestures.append(g);
3171 } else {
3172 ++i;
3173 }
3174 }
3175 if (!gestures.isEmpty()) { // we have gestures for this w
3176 QGestureEvent ge(gestures);
3177 ge.t = gestureEvent->t;
3178 ge.m_spont = gestureEvent->spontaneous();
3179 ge.m_accept = wasAccepted;
3180 ge.m_accepted = gestureEvent->m_accepted;
3181 res = d->notify_helper(w, &ge);
3182 gestureEvent->m_spont = false;
3183 eventAccepted = ge.isAccepted();
3184 for (int i = 0; i < gestures.size(); ++i) {
3185 QGesture *g = gestures.at(i);
3186 // Ignore res [event return value] because handling of multiple gestures
3187 // packed into a single QEvent depends on not consuming the event
3188 if (eventAccepted || ge.isAccepted(g)) {
3189 // if the gesture was accepted, mark the target widget for it
3190 gestureEvent->m_targetWidgets[g->gestureType()] = w;
3191 gestureEvent->setAccepted(g, true);
3192 } else {
3193 // if the gesture was explicitly ignored by the application,
3194 // put it back so a parent can get it
3195 allGestures.append(g);
3196 }
3197 }
3198 }
3199 if (allGestures.isEmpty()) // everything delivered
3200 break;
3201 if (w->isWindow())
3202 break;
3203 w = w->parentWidget();
3204 }
3205 for (QGesture *g : std::as_const(allGestures))
3206 gestureEvent->setAccepted(g, false);
3207 gestureEvent->m_accept = false; // to make sure we check individual gestures
3208 break;
3209 }
3210#endif // QT_NO_GESTURES
3211#ifdef Q_OS_MAC
3212 // Enable touch events on enter, disable on leave.
3213 typedef void (*RegisterTouchWindowFn)(QWindow *, bool);
3214 case QEvent::Enter:
3215 if (w->testAttribute(Qt::WA_AcceptTouchEvents)) {
3216 RegisterTouchWindowFn registerTouchWindow = reinterpret_cast<RegisterTouchWindowFn>
3218 if (registerTouchWindow)
3219 registerTouchWindow(w->window()->windowHandle(), true);
3220 }
3221 res = d->notify_helper(receiver, e);
3222 break;
3223 case QEvent::Leave:
3224 if (w->testAttribute(Qt::WA_AcceptTouchEvents)) {
3225 RegisterTouchWindowFn registerTouchWindow = reinterpret_cast<RegisterTouchWindowFn>
3227 if (registerTouchWindow)
3228 registerTouchWindow(w->window()->windowHandle(), false);
3229 }
3230 res = d->notify_helper(receiver, e);
3231 break;
3232#endif
3233 default:
3234 res = d->notify_helper(receiver, e);
3235 break;
3236 }
3237 } else {
3238 res = d->notify_helper(receiver, e);
3239 }
3240
3241 return res;
3242}
3243
3245{
3246 // These tracepoints (and the whole function, actually) are very similar
3247 // to the ones in QCoreApplicationPrivate::notify_helper; the reason for their
3248 // duplication is because tracepoint symbols are not exported by QtCore.
3249 // If you adjust the tracepoints here, consider adjusting QCoreApplicationPrivate too.
3250 Q_TRACE(QApplication_notify_entry, receiver, e, e->type());
3251 bool consumed = false;
3252 bool filtered = false;
3253 Q_TRACE_EXIT(QApplication_notify_exit, consumed, filtered);
3254
3255 // send to all application event filters
3257 && receiver->d_func()->threadData.loadRelaxed()->thread.loadAcquire() == mainThread()
3258 && sendThroughApplicationEventFilters(receiver, e)) {
3259 filtered = true;
3260 return filtered;
3261 }
3262
3263 if (receiver->isWidgetType()) {
3264 QWidget *widget = static_cast<QWidget *>(receiver);
3265
3266#if !defined(QT_NO_CURSOR)
3267 // toggle HasMouse widget state on enter and leave
3268 if ((e->type() == QEvent::Enter || e->type() == QEvent::DragEnter) &&
3271 else if (e->type() == QEvent::Leave || e->type() == QEvent::DragLeave)
3273#endif
3274
3275 if (QLayout *layout=widget->d_func()->layout) {
3277 }
3278 }
3279
3280 // send to all receiver event filters
3281 if (sendThroughObjectEventFilters(receiver, e)) {
3282 filtered = true;
3283 return filtered;
3284 }
3285
3286 // deliver the event
3287 consumed = receiver->event(e);
3288
3290 return consumed;
3291}
3292
3294{
3295 return QApplicationPrivate::popupWidgets != nullptr;
3296}
3297
3299{
3302 else
3303 qt_widget_private(popup)->stealKeyboardGrab(false);
3304}
3305
3306static void ungrabMouseForPopup(QWidget *popup)
3307{
3310 else
3311 qt_widget_private(popup)->stealMouseGrab(false);
3312}
3313
3314static bool popupGrabOk;
3315
3316static void grabForPopup(QWidget *popup)
3317{
3320 if (popupGrabOk) {
3322 if (!popupGrabOk) {
3323 // transfer grab back to the keyboard grabber if any
3325 }
3326 }
3327}
3328
3329extern QWidget *qt_popup_down;
3330extern bool qt_replay_popup_mouse_event;
3331extern bool qt_popup_down_closed;
3332
3334{
3335 // Close all popups: In case some popup refuses to close,
3336 // we give up after 1024 attempts (to avoid an infinite loop).
3337 int maxiter = 1024;
3338 QWidget *popup;
3339 while ((popup = QApplication::activePopupWidget()) && maxiter--)
3340 popup->close(); // this will call QApplicationPrivate::closePopup
3341 return true;
3342}
3343
3345{
3346 if (!popupWidgets)
3347 return;
3348 popupWidgets->removeAll(popup);
3349
3350 if (popup == qt_popup_down) {
3351 qt_button_down = nullptr;
3352 qt_popup_down_closed = true;
3353 qt_popup_down = nullptr;
3354 }
3355
3356 if (QApplicationPrivate::popupWidgets->size() == 0) { // this was the last popup
3359 qt_popup_down_closed = false;
3360
3361 if (popupGrabOk) {
3362 popupGrabOk = false;
3363
3364 // TODO on multi-seat window systems, we have to know which mouse
3366 auto mousePressPos = devPriv->pointById(0)->eventPoint.globalPressPosition();
3367 if (popup->geometry().contains(mousePressPos.toPoint())
3369 // mouse release event or inside
3371 } else { // mouse press event
3373 }
3374
3375 // transfer grab back to mouse grabber if any, otherwise release the grab
3376 ungrabMouseForPopup(popup);
3377
3378 // transfer grab back to keyboard grabber if any, otherwise release the grab
3380 }
3381
3382 if (active_window) {
3383 if (QWidget *fw = active_window->focusWidget()) {
3384 if (fw != QApplication::focusWidget()) {
3385 fw->setFocus(Qt::PopupFocusReason);
3386 } else {
3389 }
3390 }
3391 }
3392
3393 } else {
3394 // A popup was closed, so the previous popup gets the focus.
3396 if (QWidget *fw = aw->focusWidget())
3398
3399 // can become nullptr due to setFocus() above
3401 QApplicationPrivate::popupWidgets->size() == 1) // grab mouse/keyboard
3402 grabForPopup(aw);
3403 }
3404
3405}
3406
3408
3410{
3412 if (!popupWidgets) // create list
3414 popupWidgets->append(popup); // add to end of list
3415
3416 if (QApplicationPrivate::popupWidgets->size() == 1) // grab mouse/keyboard
3417 grabForPopup(popup);
3418
3419 // popups are not focus-handled by the window system (the first
3420 // popup grabbed the keyboard), so we have to do that manually: A
3421 // new popup gets the focus
3422 if (popup->focusWidget()) {
3424 } else if (popupWidgets->size() == 1) { // this was the first popup
3425 if (QWidget *fw = QApplication::focusWidget()) {
3428 }
3429 }
3430}
3431
3432#ifdef QT_KEYPAD_NAVIGATION
3440void QApplication::setNavigationMode(Qt::NavigationMode mode)
3441{
3442 QApplicationPrivate::navigationMode = mode;
3443}
3444
3452Qt::NavigationMode QApplication::navigationMode()
3453{
3454 return QApplicationPrivate::navigationMode;
3455}
3456#endif
3457
3481{
3482 if (widget) {
3484 return;
3486 window->alert(duration);
3487 } else {
3488 const auto topLevels = topLevelWidgets();
3489 for (QWidget *topLevel : topLevels)
3490 QApplication::alert(topLevel, duration);
3491 }
3492}
3493
3513{
3515}
3516
3518{
3520}
3521
3531{
3533}
3534
3536{
3538}
3539
3550{
3552}
3553
3555{
3557}
3558
3576#if QT_CONFIG(wheelevent)
3577int QApplication::wheelScrollLines()
3578{
3579 return styleHints()->wheelScrollLines();
3580}
3581
3582void QApplication::setWheelScrollLines(int lines)
3583{
3585}
3586#endif
3587
3589{
3590 switch (effect) {
3591 case Qt::UI_General:
3593 case Qt::UI_AnimateMenu:
3595 case Qt::UI_FadeMenu:
3601 case Qt::UI_FadeTooltip:
3605 }
3606 return 0;
3607}
3608
3621{
3622 int effectFlags = uiEffectToFlag(effect);
3623 if (enable) {
3624 if (effectFlags & QPlatformTheme::FadeMenuUiEffect)
3626 if (effectFlags & QPlatformTheme::FadeTooltipUiEffect)
3629 } else {
3631 }
3632}
3633
3648{
3649 CHECK_QAPP_INSTANCE(false)
3650 return QColormap::instance().depth() >= 16
3653}
3654
3662{
3664}
3665
3678{
3679 return QGuiApplication::sendSpontaneousEvent(receiver, event);
3680}
3681
3682void QApplicationPrivate::giveFocusAccordingToFocusPolicy(QWidget *widget, QEvent *event, QPoint localPos)
3683{
3684 const bool setFocusOnRelease = QGuiApplication::styleHints()->setFocusOnTouchRelease();
3685 Qt::FocusPolicy focusPolicy = Qt::ClickFocus;
3686 static QPointer<QWidget> focusedWidgetOnTouchBegin = nullptr;
3687
3688 switch (event->type()) {
3691 case QEvent::TouchBegin:
3692 focusedWidgetOnTouchBegin = QApplication::focusWidget();
3693 if (setFocusOnRelease)
3694 return;
3695 break;
3697 case QEvent::TouchEnd:
3698 if (!setFocusOnRelease)
3699 return;
3700 if (focusedWidgetOnTouchBegin != QApplication::focusWidget()) {
3701 // Focus widget was changed while delivering press/move events.
3702 // To not interfere with application logic, we leave focus as-is
3703 return;
3704 }
3705 break;
3706 case QEvent::Wheel:
3707 focusPolicy = Qt::WheelFocus;
3708 break;
3709 default:
3710 return;
3711 }
3712
3713 QWidget *focusWidget = widget;
3714 while (focusWidget) {
3715 if (focusWidget->isEnabled()
3716 && focusWidget->rect().contains(localPos)
3717 && QApplicationPrivate::shouldSetFocus(focusWidget, focusPolicy)) {
3718 focusWidget->setFocus(Qt::MouseFocusReason);
3719 break;
3720 }
3721 if (focusWidget->isWindow())
3722 break;
3723
3724 // find out whether this widget (or its proxy) already has focus
3725 QWidget *f = focusWidget;
3726 if (focusWidget->d_func()->extra && focusWidget->d_func()->extra->focus_proxy)
3727 f = focusWidget->d_func()->extra->focus_proxy;
3728 // if it has, stop here.
3729 // otherwise a click on the focused widget would remove its focus if ClickFocus isn't set
3730 if (f->hasFocus())
3731 break;
3732
3733 localPos += focusWidget->pos();
3734 focusWidget = focusWidget->parentWidget();
3735 }
3736}
3737
3738bool QApplicationPrivate::shouldSetFocus(QWidget *w, Qt::FocusPolicy policy)
3739{
3740 QWidget *f = w;
3741 while (f->d_func()->extra && f->d_func()->extra->focus_proxy)
3742 f = f->d_func()->extra->focus_proxy;
3743
3744 if ((w->focusPolicy() & policy) != policy)
3745 return false;
3746 if (w != f && (f->focusPolicy() & policy) != policy)
3747 return false;
3748 return true;
3749}
3750
3752{
3753 bool containsPress = false;
3754
3755 for (int i = 0; i < touchEvent->pointCount(); ++i) {
3756 auto &pt = touchEvent->point(i);
3757 QMutableEventPoint::setPosition(pt, widget->mapFromGlobal(pt.globalPosition()));
3758
3759 if (pt.state() == QEventPoint::State::Pressed)
3760 containsPress = true;
3761 }
3762 return containsPress;
3763}
3764
3766{
3768}
3769
3771{
3772}
3773
3775{
3777}
3778
3780{
3781}
3782
3784{
3785 const QPointF globalPos = touchPoint.globalPosition();
3786 int closestTouchPointId = -1;
3787 QObject *closestTarget = nullptr;
3788 qreal closestDistance = 0;
3790 for (auto &epd : devPriv->activePoints.values()) {
3791 const auto &pt = epd.eventPoint;
3792 if (pt.id() != touchPoint.id()) {
3793 qreal dx = globalPos.x() - pt.globalPosition().x();
3794 qreal dy = globalPos.y() - pt.globalPosition().y();
3795 qreal distance = dx * dx + dy * dy;
3796 if (closestTouchPointId == -1 || distance < closestDistance) {
3797 closestTouchPointId = pt.id();
3798 closestDistance = distance;
3799 closestTarget = QMutableEventPoint::target(pt);
3800 }
3801 }
3802 }
3803 return static_cast<QWidget *>(closestTarget);
3804}
3805
3807 ImplicitTouchGrabMode grabMode)
3808{
3809 if (touchEvent->type() != QEvent::TouchBegin)
3810 return;
3811
3812 // If the widget dispatched the event further (see QGraphicsProxyWidget), then
3813 // there might already be an implicit grabber. Don't override that. A widget that
3814 // has partially recognized a gesture needs to grab all points.
3815 for (int i = 0; i < touchEvent->pointCount(); ++i) {
3816 auto &ep = touchEvent->point(i);
3817 if (!QMutableEventPoint::target(ep) && (ep.isAccepted() || grabMode == GrabAllPoints))
3818 QMutableEventPoint::setTarget(ep, widget);
3819 }
3820 // TODO setExclusiveGrabber() to be consistent with Qt Quick?
3821}
3822
3824{
3825 QApplicationPrivate *d = self;
3826 // TODO get rid of this QPair
3827 typedef QPair<QEventPoint::State, QList<QEventPoint> > StatesAndTouchPoints;
3828 QHash<QWidget *, StatesAndTouchPoints> widgetsNeedingEvents;
3829
3830 const auto *device = te->pointingDevice();
3831 auto touchPoints = te->points(); // touch points will be mutated
3832 for (auto &touchPoint : touchPoints) {
3833 // update state
3835 if (touchPoint.state() == QEventPoint::State::Pressed) {
3837 // on touchpads, send all touch points to the same widget:
3838 // pick the first non-null target if possible
3840 }
3841
3842 if (target.isNull()) {
3843 // determine which widget this event will go to
3844 if (!window)
3845 window = QApplication::topLevelAt(touchPoint.globalPosition().toPoint());
3846 if (!window)
3847 continue;
3848 target = window->childAt(window->mapFromGlobal(touchPoint.globalPosition().toPoint()));
3849 if (!target)
3850 target = window;
3851 }
3852
3853 bool usingClosestWidget = false;
3855 QWidget *closestWidget = d->findClosestTouchPointTarget(device, touchPoint);
3856 QWidget *widget = static_cast<QWidget *>(target.data());
3857 if (closestWidget
3858 && (widget->isAncestorOf(closestWidget) || closestWidget->isAncestorOf(widget))) {
3859 target = closestWidget;
3860 usingClosestWidget = true;
3861 }
3862 }
3863
3864 // on touch pads, implicitly grab all touch points
3865 // on touch screens, grab touch points that are redirected to the closest widget
3866 if (device->type() == QInputDevice::DeviceType::TouchPad || usingClosestWidget)
3867 QMutableEventPoint::setTarget(touchPoint, target);
3868 } else {
3869 target = QMutableEventPoint::target(touchPoint);
3870 if (!target)
3871 continue;
3872 }
3873 Q_ASSERT(!target.isNull());
3874
3875 QWidget *targetWidget = static_cast<QWidget *>(target.data());
3876
3877#ifdef Q_OS_MACOS
3878 // Single-touch events are normally not sent unless WA_TouchPadAcceptSingleTouchEvents is set.
3879 // In Qt 4 this check was in OS X-only code. That behavior is preserved here by the #ifdef.
3880 if (touchPoints.count() == 1
3883 continue;
3884#endif
3885
3886 StatesAndTouchPoints &maskAndPoints = widgetsNeedingEvents[targetWidget];
3887 maskAndPoints.first = QEventPoint::State(maskAndPoints.first | touchPoint.state());
3888 maskAndPoints.second.append(touchPoint);
3889 }
3890
3891 if (widgetsNeedingEvents.isEmpty())
3892 return false;
3893
3894 bool accepted = false;
3897 for (; it != end; ++it) {
3898 const QPointer<QWidget> widget = it.key();
3900 continue;
3901
3902 QEvent::Type eventType;
3903 switch (it.value().first) {
3905 eventType = QEvent::TouchBegin;
3906 break;
3908 eventType = QEvent::TouchEnd;
3909 break;
3911 // don't send the event if nothing changed
3912 continue;
3913 default:
3914 eventType = QEvent::TouchUpdate;
3915 break;
3916 }
3917
3919 it.value().second);
3920 bool containsPress = updateTouchPointsForWidget(widget, &touchEvent);
3921 touchEvent.setTimestamp(te->timestamp());
3922 touchEvent.setTarget(widget);
3923
3924 if (containsPress)
3926
3927 switch (touchEvent.type()) {
3928 case QEvent::TouchBegin:
3929 {
3930 // if the TouchBegin handler recurses, we assume that means the event
3931 // has been implicitly accepted and continue to send touch events
3932 bool res = te->spontaneous() ? QApplication::sendSpontaneousEvent(widget, &touchEvent)
3933 : QApplication::sendEvent(widget, &touchEvent);
3934 if (res && touchEvent.isAccepted()) {
3935 accepted = true;
3936 if (!widget.isNull())
3938 }
3939 break;
3940 }
3941 default:
3943#ifndef QT_NO_GESTURES
3945#endif
3946 ) {
3947 bool res = te->spontaneous() ? QApplication::sendSpontaneousEvent(widget, &touchEvent)
3948 : QApplication::sendEvent(widget, &touchEvent);
3949 if (res && touchEvent.isAccepted())
3950 accepted = true;
3951 // widget can be deleted on TouchEnd
3952 if (touchEvent.type() == QEvent::TouchEnd && !widget.isNull())
3954 }
3955 break;
3956 }
3957 }
3958 return accepted;
3959}
3960
3962{
3964 touchEvent.setTimestamp(timestamp);
3965
3966 QSet<QWidget *> widgetsNeedingCancel;
3968 for (auto &epd : devPriv->activePoints.values()) {
3969 const auto &pt = epd.eventPoint;
3971 if (target && target->isWidgetType())
3972 widgetsNeedingCancel.insert(static_cast<QWidget *>(target));
3973 }
3974 for (QSet<QWidget *>::const_iterator widIt = widgetsNeedingCancel.constBegin(),
3975 widItEnd = widgetsNeedingCancel.constEnd(); widIt != widItEnd; ++widIt) {
3976 QWidget *widget = *widIt;
3977 touchEvent.setTarget(widget);
3978 QApplication::sendSpontaneousEvent(widget, &touchEvent);
3979 }
3980}
3981
3983{
3985
3987}
3988
3989#if QT_CONFIG(draganddrop)
3990void QApplicationPrivate::notifyDragStarted(const QDrag *drag)
3991{
3992 QGuiApplicationPrivate::notifyDragStarted(drag);
3993 // QTBUG-26145
3994 // Prevent pickMouseReceiver() from using the widget where the drag was started after a drag operation...
3995 // QTBUG-56713
3996 // ...only if qt_button_down is not a QQuickWidget
3997 if (qt_button_down && !qt_button_down->inherits("QQuickWidget"))
3998 qt_button_down = nullptr;
3999}
4000#endif // QT_CONFIG(draganddrop)
4001
4002#ifndef QT_NO_GESTURES
4004{
4006 if (!qAppPriv)
4007 return nullptr;
4008 if (!qAppPriv->gestureManager && ic == ForceCreation)
4009 qAppPriv->gestureManager = new QGestureManager(qApp);
4010 return qAppPriv->gestureManager;
4011}
4012#endif // QT_NO_GESTURES
4013
4015{
4016 QStyleOption opt(0);
4019}
4020
4021void *QApplication::resolveInterface(const char *name, int revision) const
4022{
4023 return QGuiApplication::resolveInterface(name, revision);
4024}
4025
4027
4028#include "moc_qapplication.cpp"
IOBluetoothDevice * device
static void(* setWidgetParent)(QObject *, QObject *)
Definition qobject_p.h:70
static QWidget * pickMouseReceiver(QWidget *candidate, const QPoint &windowPos, QPoint *pos, QEvent::Type type, Qt::MouseButtons buttons, QWidget *buttonDown, QWidget *alienWidget)
virtual void notifyLayoutDirectionChange() override
static void initializeWidgetPalettesFromTheme()
static QApplicationPrivate * instance()
void handlePaletteChanged(const char *className=nullptr) override
void sendSyntheticEnterLeave(QWidget *widget)
static QWidget * desktop()
static bool modalState()
static QWidget * focus_widget
static QPointer< QWidget > leaveAfterRelease
QGestureManager * gestureManager
static void initializeWidgetFontHash()
bool notify_helper(QObject *receiver, QEvent *e)
virtual void notifyActiveWindowChange(QWindow *) override
static QWidget * hidden_focus_widget
QPalette basePalette() const override
static QWidget * active_window
static void setFocusWidget(QWidget *focus, Qt::FocusReason reason)
void closePopup(QWidget *popup)
static PaletteHash widgetPalettes
static int enabledAnimations
static QWidget * focusNextPrevChild_helper(QWidget *toplevel, bool next, bool *wrappingOccurred=nullptr)
internal Helper function that returns the new focus widget, but does not set the focus reason.
static QString styleSheet
Qt::WindowModality defaultModality() const override
QPixmap applyQIconStyleHelper(QIcon::Mode mode, const QPixmap &base) const override
static bool inPopupMode()
static QWindow * windowForWidget(const QWidget *widget)
static QFont * sys_font
void handleThemeChanged() override
void openPopup(QWidget *popup)
static QWidgetList * popupWidgets
void activateImplicitTouchGrab(QWidget *widget, QTouchEvent *touchBeginEvent, ImplicitTouchGrabMode grabMode=GrabAcceptedPoints)
void notifyWindowIconChanged() override
QWidget * findClosestTouchPointTarget(const QPointingDevice *device, const QEventPoint &touchPoint)
bool closeAllPopups() override
static void dispatchEnterLeave(QWidget *enter, QWidget *leave, const QPointF &globalPosF)
static QString desktopStyleKey()
static bool isBlockedByModal(QWidget *widget)
static QStyle * app_style
void createEventDispatcher() override
static QWidget * main_widget
static bool translateRawTouchEvent(QWidget *widget, const QTouchEvent *touchEvent)
static bool sendMouseEvent(QWidget *receiver, QMouseEvent *event, QWidget *alienWidget, QWidget *native, QWidget **buttonDown, QPointer< QWidget > &lastMouseReceiver, bool spontaneous=true, bool onlyDispatchEnterLeave=false)
static void setSystemFont(const QFont &font)
static bool autoSipEnabled
static bool updateTouchPointsForWidget(QWidget *widget, QTouchEvent *touchEvent)
static void setActiveWindow(QWidget *act)
static bool tryModalHelper(QWidget *widget, QWidget **rettop=nullptr)
bool windowNeverBlocked(QWindow *window) const override
QApplicationPrivate(int &argc, char **argv)
static QFont * set_font
void initialize()
Initializes the QApplication object, called from the constructors.
static void translateTouchCancel(const QPointingDevice *device, ulong timestamp)
The QApplication class manages the GUI application's control flow and main settings.
static QStyle * style()
Returns the application's style object.
static void setStyle(QStyle *)
Sets the application's GUI style to style.
static void aboutQt()
Displays a simple message box about Qt.
static void closeAllWindows()
Closes all top-level windows.
static void beep()
Sounds the bell, using the default volume and sound.
virtual ~QApplication()
Cleans up any window system resources that were allocated by this application.
static bool isEffectEnabled(Qt::UIEffect)
Returns true if effect is enabled; otherwise returns false.
static void setPalette(const QPalette &, const char *className=nullptr)
Changes the application palette to palette.
static QWidget * widgetAt(const QPoint &p)
Returns the widget at global screen position point, or \nullptr if there is no Qt widget there.
static void alert(QWidget *widget, int duration=0)
static QPalette palette()
Returns the current application palette.
static QWidget * activeModalWidget()
Returns the active modal widget.
static QWidget * topLevelAt(const QPoint &p)
Returns the top-level widget at the given point; returns \nullptr if there is no such widget.
static QWidget * focusWidget()
Returns the application widget that has the keyboard input focus, or \nullptr if no widget in this ap...
static QWidgetList topLevelWidgets()
Returns a list of the top-level widgets (windows) in the application.
static QFont font()
Returns the default application font.
bool autoSipEnabled
toggles automatic SIP (software input panel) visibility
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 QWidget * activePopupWidget()
Returns the active popup widget.
static int exec()
Enters the main event loop and waits until exit() is called, then returns the value that was set to e...
int startDragTime
the time in milliseconds that a mouse button must be held down before a drag and drop operation will ...
static void setCursorFlashTime(int)
bool qt_sendSpontaneousEvent(QObject *receiver, QEvent *event)
\macro qApp
int doubleClickInterval
the time limit in milliseconds that distinguishes a double click from two consecutive mouse clicks
int cursorFlashTime
the text cursor's flash (blink) time in milliseconds
static void setStartDragTime(int ms)
int startDragDistance
the minimum distance required for a drag and drop operation to start.
bool event(QEvent *) override
\reimp
void setAutoSipEnabled(const bool enabled)
bool notify(QObject *, QEvent *) override
\reimp
static void setStartDragDistance(int l)
static QWidget * activeWindow()
Returns the application top-level window that has the keyboard input focus, or \nullptr if no applica...
bool compressEvent(QEvent *, QObject *receiver, QPostEventList *) override
int keyboardInputInterval
the time limit in milliseconds that distinguishes a key press from two consecutive key presses
void setStyleSheet(const QString &sheet)
QString styleSheet
the application style sheet
static void setKeyboardInputInterval(int)
static void setFont(const QFont &, const char *className=nullptr)
Changes the default application font to font.
static void setDoubleClickInterval(int)
static QWidgetList allWidgets()
Returns a list of all the widgets in the application.
static void cleanup()
Definition qcolormap.cpp:47
static void initialize()
Definition qcolormap.cpp:28
static QColormap instance(int screen=-1)
Definition qcolormap.cpp:53
int depth() const
Definition qcolormap.cpp:76
The QContextMenuEvent class contains parameters that describe a context menu event.
Definition qevent.h:593
static void setEventSpontaneous(QEvent *e, bool spontaneous)
QCoreApplicationPrivate::Type application_type
bool sendThroughApplicationEventFilters(QObject *, QEvent *)
static bool sendThroughObjectEventFilters(QObject *, QEvent *)
static void checkReceiverThread(QObject *receiver)
static QAbstractEventDispatcher * eventDispatcher
static bool testAttribute(uint flag)
static QThread * mainThread()
static bool threadRequiresCoreApplication()
void * resolveInterface(const char *name, int revision) const
\macro Q_DECLARE_TR_FUNCTIONS(context)
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
bool event(QEvent *) override
\reimp
static void setAttribute(Qt::ApplicationAttribute attribute, bool on=true)
Sets the attribute attribute if on is true; otherwise clears the attribute.
static QCoreApplication * instance() noexcept
Returns a pointer to the application's QCoreApplication (or QGuiApplication/QApplication) instance.
friend class QApplication
static void postEvent(QObject *receiver, QEvent *event, int priority=Qt::NormalEventPriority)
static QPoint pos()
Returns the position of the cursor (hot spot) of the primary screen in global screen coordinates.
Definition qcursor.cpp:188
void setCurrentTarget(QObject *target, bool dropped=false)
Definition qdnd.cpp:44
static QDragManager * self()
Definition qdnd.cpp:30
\inmodule QtGui
Definition qdrag.h:22
\inmodule QtGui
Definition qevent.h:164
The QEventPoint class provides information about a point in a QPointerEvent.
Definition qeventpoint.h:20
QPointF globalPosition
the global position of this point.
Definition qeventpoint.h:44
int id
the ID number of this event point.
Definition qeventpoint.h:25
State
Specifies the state of this event point.
Definition qeventpoint.h:49
\inmodule QtCore
Definition qcoreevent.h:45
bool spontaneous() const
Returns true if the event originated outside the application (a system event); otherwise returns fals...
Definition qcoreevent.h:300
Type
This enum type defines the valid event types in Qt.
Definition qcoreevent.h:51
@ QueryWhatsThis
Definition qcoreevent.h:169
@ OrientationChange
Definition qcoreevent.h:262
@ TabletMove
Definition qcoreevent.h:121
@ MetaCall
Definition qcoreevent.h:97
@ GraphicsSceneDragLeave
Definition qcoreevent.h:200
@ ApplicationPaletteChange
Definition qcoreevent.h:93
@ CloseSoftwareInputPanel
Definition qcoreevent.h:249
@ ApplicationDeactivate
Definition qcoreevent.h:166
@ StatusTip
Definition qcoreevent.h:149
@ GestureOverride
Definition qcoreevent.h:254
@ DragResponse
Definition qcoreevent.h:105
@ FocusAboutToChange
Definition qcoreevent.h:68
@ EnterWhatsThisMode
Definition qcoreevent.h:170
@ ChildPolished
Definition qcoreevent.h:107
@ ApplicationLayoutDirectionChange
Definition qcoreevent.h:92
@ GraphicsSceneDragEnter
Definition qcoreevent.h:198
@ GraphicsSceneDragMove
Definition qcoreevent.h:199
@ ApplicationWindowIconChange
Definition qcoreevent.h:90
@ ShortcutOverride
Definition qcoreevent.h:158
@ FocusOut
Definition qcoreevent.h:67
@ ChildRemoved
Definition qcoreevent.h:108
@ DeferredDelete
Definition qcoreevent.h:100
@ StyleChange
Definition qcoreevent.h:136
@ NativeGesture
Definition qcoreevent.h:246
@ DragEnter
Definition qcoreevent.h:101
@ LocaleChange
Definition qcoreevent.h:122
@ LayoutRequest
Definition qcoreevent.h:112
@ KeyRelease
Definition qcoreevent.h:65
@ MouseMove
Definition qcoreevent.h:63
@ KeyPress
Definition qcoreevent.h:64
@ FocusIn
Definition qcoreevent.h:66
@ TouchCancel
Definition qcoreevent.h:264
@ ActivationChange
Definition qcoreevent.h:135
@ MouseButtonPress
Definition qcoreevent.h:60
@ TouchUpdate
Definition qcoreevent.h:242
@ TouchBegin
Definition qcoreevent.h:241
@ HoverLeave
Definition qcoreevent.h:176
@ HoverEnter
Definition qcoreevent.h:175
@ WindowActivate
Definition qcoreevent.h:83
@ LanguageChange
Definition qcoreevent.h:123
@ TabletRelease
Definition qcoreevent.h:127
@ DynamicPropertyChange
Definition qcoreevent.h:207
@ UpdateRequest
Definition qcoreevent.h:113
@ DragLeave
Definition qcoreevent.h:103
@ RequestSoftwareInputPanel
Definition qcoreevent.h:248
@ GraphicsSceneDrop
Definition qcoreevent.h:201
@ WhatsThisClicked
Definition qcoreevent.h:160
@ UpdateLater
Definition qcoreevent.h:114
@ HoverMove
Definition qcoreevent.h:177
@ TabletPress
Definition qcoreevent.h:126
@ MouseButtonDblClick
Definition qcoreevent.h:62
@ NetworkReplyUpdated
Definition qcoreevent.h:231
@ ApplicationFontChange
Definition qcoreevent.h:91
@ WhatsThis
Definition qcoreevent.h:148
@ WindowDeactivate
Definition qcoreevent.h:84
@ ContextMenu
Definition qcoreevent.h:119
@ MouseButtonRelease
Definition qcoreevent.h:61
@ ChildAdded
Definition qcoreevent.h:106
Type type() const
Returns the event type.
Definition qcoreevent.h:299
bool isAccepted() const
Definition qcoreevent.h:303
quint16 t
Definition qcoreevent.h:323
const mapped_container_type & values() const noexcept
Definition qflatmap_p.h:583
The QFocusEvent class contains event parameters for widget focus events.
Definition qevent.h:469
\reentrant \inmodule QtGui
\reentrant
Definition qfont.h:20
bool isCopyOf(const QFont &) const
Returns true if this font and f are copies of each other, i.e.
Definition qfont.cpp:1845
The QGestureEvent class provides the description of triggered gestures.
Definition qgesture.h:244
bool isAccepted(QGesture *) const
Returns true if the gesture is accepted; otherwise returns false.
Definition qgesture.cpp:962
QList< QGesture * > gestures() const
Returns all gestures that are delivered in the event.
Definition qgesture.cpp:868
void setAccepted(QGesture *, bool)
Sets the accept flag of the given gesture object to the specified value.
Definition qgesture.cpp:923
static bool gesturePending(QObject *o)
static QGestureManager * instance(InstanceCreation ic=ForceCreation)
The QGesture class represents a gesture, containing properties that describe the corresponding user i...
Definition qgesture.h:29
static QPlatformIntegration * platformIntegration()
bool isWindowBlocked(QWindow *window, QWindow **blockingWindow=nullptr) const
static void captureGlobalModifierState(QEvent *e)
virtual void handlePaletteChanged(const char *className=nullptr)
static QWindow * focus_window
void createEventDispatcher() override
Called from QCoreApplication::init()
virtual void handleThemeChanged()
static bool sendQWindowEventToQPlatformWindow(QWindow *window, QEvent *event)
static QPlatformTheme * platformTheme()
\macro qGuiApp
static QPlatformNativeInterface * platformNativeInterface()
static QWindowList topLevelWindows()
Returns a list of the top-level windows in the application.
static QWindow * modalWindow()
Returns the most recently shown modal window.
static QWindow * topLevelAt(const QPoint &pos)
Returns the top level window at the given position pos, if any.
static void setFont(const QFont &)
Changes the default application font to font.
static QPalette palette()
Returns the current application palette.
static void setPalette(const QPalette &pal)
Changes the application palette to pal.
static QFont font()
Returns the default application font.
bool compressEvent(QEvent *, QObject *receiver, QPostEventList *) override
static QStyleHints * styleHints()
Returns the application's style hints.
static QInputMethod * inputMethod()
returns the input method.
static Qt::KeyboardModifiers keyboardModifiers()
Returns the current state of the modifier keys on the keyboard.
bool event(QEvent *) override
\reimp
static bool desktopSettingsAware()
Returns true if Qt is set to use the system's standard colors, fonts, etc.; otherwise returns false.
static int exec()
Enters the main event loop and waits until exit() is called, and then returns the value that was set ...
\inmodule QtCore
Definition qhash.h:1135
const_iterator constEnd() const noexcept
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item after the ...
Definition qhash.h:1209
const_iterator constBegin() const noexcept
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first item in the hash.
Definition qhash.h:1205
friend class const_iterator
Definition qhash.h:1172
void clear() noexcept(std::is_nothrow_destructible< Node >::value)
Removes all items from the hash and frees up all memory used by it.
Definition qhash.h:949
bool isEmpty() const noexcept
Returns true if the hash contains no items; otherwise returns false.
Definition qhash.h:926
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition qhash.h:1283
The QHelpEvent class provides an event that is used to request helpful information about a particular...
Definition qevent.h:787
\inmodule QtGui
Definition qevent.h:245
Mode
This enum type describes the mode for which a pixmap is intended to be used.
Definition qicon.h:22
DeviceType type
quint64 timestamp() const
Returns the window system's timestamp for this event.
Definition qevent.h:58
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifier flags that existed immediately before the event occurred.
Definition qevent.h:56
void show()
Requests virtual keyboard to open.
void hide()
Requests virtual keyboard to close.
void commit()
Commits the word user is currently composing to the editor.
The QKeyEvent class describes a key event.
Definition qevent.h:423
int count() const
Returns the number of keys involved in this event.
Definition qevent.h:444
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifier flags that existed immediately after the event occurred.
Definition qevent.cpp:1465
QString text() const
Returns the Unicode text that this key generated.
Definition qevent.h:442
bool isAutoRepeat() const
Returns true if this event comes from an auto-repeating key; returns false if it comes from an initia...
Definition qevent.h:443
int key() const
Returns the code of the key that was pressed or released.
Definition qevent.h:433
The QLayout class is the base class of geometry managers.
Definition qlayout.h:26
void widgetEvent(QEvent *)
Definition qlayout.cpp:520
qsizetype size() const noexcept
Definition qlist.h:386
bool isEmpty() const noexcept
Definition qlist.h:390
void removeAt(qsizetype i)
Definition qlist.h:573
const T & constLast() const noexcept
Definition qlist.h:633
bool removeOne(const AT &t)
Definition qlist.h:581
const_reference at(qsizetype i) const noexcept
Definition qlist.h:429
const_reverse_iterator crbegin() const noexcept
Definition qlist.h:621
const_iterator constBegin() const noexcept
Definition qlist.h:615
qsizetype removeAll(const AT &t)
Definition qlist.h:575
void append(parameter_type t)
Definition qlist.h:441
const_iterator constEnd() const noexcept
Definition qlist.h:616
const_iterator ConstIterator
Definition qlist.h:251
const_reverse_iterator crend() const noexcept
Definition qlist.h:622
T & value() const
Definition qmap.h:442
iterator find(const Key &key)
Definition qmap.h:640
iterator end()
Definition qmap.h:601
static void aboutQt(QWidget *parent, const QString &title=QString())
Displays a simple message box about Qt, with the given title and centered over parent (if parent is n...
\inmodule QtGui
Definition qevent.h:195
Qt::MouseEventSource source() const
Definition qevent.cpp:798
The QMoveEvent class contains event parameters for move events.
Definition qevent.h:501
const QPoint & pos() const
Returns the new position of the widget.
Definition qevent.h:506
static QObject * target(const QEventPoint &p)
void setDoubleClick(bool d=true)
Definition qevent_p.h:65
static QMutableSinglePointEvent * from(QSinglePointEvent *e)
Definition qevent_p.h:57
static QMutableTouchEvent * from(QTouchEvent *e)
Definition qevent_p.h:37
QObject * parent
Definition qobject.h:61
\inmodule QtCore
Definition qobject.h:90
bool isWindowType() const
Returns true if the object is a window; otherwise returns false.
Definition qobject.h:119
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:311
virtual bool event(QEvent *event)
This virtual function receives events to an object and should return true if the event e was recogniz...
Definition qobject.cpp:1363
void setParent(QObject *parent)
Makes the object a child of parent.
Definition qobject.cpp:2142
QThread * thread() const
Returns the thread in which the object lives.
Definition qobject.cpp:1561
bool inherits(const char *classname) const
Returns true if this object is an instance of a class that inherits className or a QObject subclass t...
Definition qobject.h:313
bool isWidgetType() const
Returns true if the object is a widget; otherwise returns false.
Definition qobject.h:118
The QPalette class contains color groups for each widget state.
Definition qpalette.h:19
void setResolveMask(ResolveMask mask)
ResolveMask resolveMask() const
static void clear()
Removes all pixmaps from the cache.
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
Definition qpixmap.h:27
virtual void beep() const
virtual NativeResourceForIntegrationFunction nativeResourceFunctionForIntegration(const QByteArray &resource)
The QPlatformTheme class allows customizing the UI based on themes.
virtual const QPalette * palette(Palette type=SystemPalette) const
virtual const QFont * font(Font type=SystemFont) const
\inmodule QtCore\reentrant
Definition qpoint.h:214
constexpr qreal x() const noexcept
Returns the x coordinate of this point.
Definition qpoint.h:333
constexpr qreal y() const noexcept
Returns the y coordinate of this point.
Definition qpoint.h:338
constexpr QPoint toPoint() const
Rounds the coordinates of this point to the nearest integer, and returns a QPoint object with the rou...
Definition qpoint.h:394
\inmodule QtCore\reentrant
Definition qpoint.h:23
constexpr int x() const noexcept
Returns the x coordinate of this point.
Definition qpoint.h:127
constexpr int y() const noexcept
Returns the y coordinate of this point.
Definition qpoint.h:132
const QPointingDevice * pointingDevice() const
Returns the source device from which this event originates.
Definition qevent.cpp:327
void setTimestamp(quint64 timestamp) override
Definition qevent.cpp:335
QEventPoint & point(qsizetype i)
Returns a QEventPoint reference for the point at index i.
Definition qevent.cpp:237
virtual void setAccepted(bool accepted) override
\reimp
Definition qevent.cpp:315
const QList< QEventPoint > & points() const
Returns a list of points in this pointer event.
Definition qevent.h:86
\inmodule QtCore
Definition qpointer.h:18
bool isNull() const
Returns true if the referenced object has been destroyed or if there is no referenced object; otherwi...
Definition qpointer.h:67
QObject * firstActiveTarget() const
static QPointingDevicePrivate * get(QPointingDevice *q)
The QPointingDevice class describes a device from which mouse, touch or tablet events originate.
static const QPointingDevice * primaryPointingDevice(const QString &seatName=QString())
Returns the primary pointing device (the core pointer, traditionally assumed to be a mouse) on the gi...
\inmodule QtCore\reentrant
Definition qrect.h:483
bool contains(const QRectF &r) const noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qrect.cpp:1985
bool contains(const QRect &r, bool proper=false) const noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qrect.cpp:851
The QRegion class specifies a clip region for a painter.
Definition qregion.h:27
bool isEmpty() const
Returns true if the region is empty; otherwise returns false.
The QResizeEvent class contains event parameters for resize events.
Definition qevent.h:547
const QSize & size() const
Returns the new size of the widget.
Definition qevent.h:552
QList< T > values() const
Definition qset.h:297
const_iterator ConstIterator
Definition qset.h:153
const_iterator constBegin() const noexcept
Definition qset.h:139
const_iterator constEnd() const noexcept
Definition qset.h:143
const_iterator constFind(const T &value) const
Definition qset.h:161
iterator insert(const T &value)
Definition qset.h:155
QPointF globalPosition() const
Returns the position of the point in this event on the screen or virtual desktop.
Definition qevent.h:122
QPointF position() const
Returns the position of the point in this event, relative to the widget or item that received the eve...
Definition qevent.h:118
QPointF scenePosition() const
Returns the position of the point in this event, relative to the window or scene.
Definition qevent.h:120
Qt::MouseButton button() const
Returns the button that caused the event.
Definition qevent.h:115
Qt::MouseButtons buttons() const
Returns the button state when the event was generated.
Definition qevent.h:116
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
static QString fromLocal8Bit(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:5788
void clear()
Clears the contents of the string and makes it null.
Definition qstring.h:1107
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition qstring.h:1083
QString toLower() const &
Definition qstring.h:368
QString & append(QChar c)
Definition qstring.cpp:3227
static QStringList keys()
Returns the list of valid keys, i.e.
static QStyle * create(const QString &)
void setKeyboardInputInterval(int keyboardInputInterval)
Sets the keyboardInputInterval.
void setWheelScrollLines(int scrollLines)
Sets the wheelScrollLines.
int keyboardInputInterval
the time limit, in milliseconds, that distinguishes a key press from two consecutive key presses.
Definition qstylehints.h:27
void setStartDragDistance(int startDragDistance)
Sets the startDragDistance.
int startDragTime
the time, in milliseconds, that a mouse button must be held down before a drag and drop operation wil...
Definition qstylehints.h:40
int startDragDistance
the distance, in pixels, that the mouse must be moved with a button held down before a drag and drop ...
Definition qstylehints.h:39
bool setFocusOnTouchRelease
the event that should set input focus on focus objects.
Definition qstylehints.h:34
Qt::TabFocusBehavior tabFocusBehavior
The focus behavior on press of the tab key.
Definition qstylehints.h:44
void setCursorFlashTime(int cursorFlashTime)
Sets the cursorFlashTime.
int mouseDoubleClickInterval
the time limit in milliseconds that distinguishes a double click from two consecutive mouse clicks.
Definition qstylehints.h:29
int cursorFlashTime
the text cursor's flash (blink) time in milliseconds.
Definition qstylehints.h:20
int wheelScrollLines
Number of lines to scroll by default for each wheel click.
Definition qstylehints.h:48
void setMouseDoubleClickInterval(int mouseDoubleClickInterval)
Sets the mouseDoubleClickInterval.
void setStartDragTime(int startDragTime)
Sets the startDragDragTime.
The QStyleOption class stores the parameters used by QStyle functions.
QPalette palette
void repolish(QWidget *widget)
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI.
Definition qstyle.h:29
virtual void polish(QWidget *widget)
Initializes the appearance of the given widget.
Definition qstyle.cpp:436
virtual QPalette standardPalette() const
Returns the style's standard palette.
Definition qstyle.cpp:2302
@ SH_Widget_ShareActivation
Definition qstyle.h:606
@ SH_ToolTip_FallAsleepDelay
Definition qstyle.h:682
@ SH_ToolTip_WakeUpDelay
Definition qstyle.h:681
virtual QPixmap generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &pixmap, const QStyleOption *opt) const =0
Returns a copy of the given pixmap, styled to conform to the specified iconMode and taking into accou...
virtual void unpolish(QWidget *widget)
Uninitialize the given {widget}'s appearance.
Definition qstyle.cpp:455
QEventPoint & point(int touchId)
QMap< int, QEventPoint > points
static QThread * currentThread()
Definition qthread.cpp:966
\inmodule QtCore
Definition qcoreevent.h:359
int timerId() const
Returns the unique timer identifier, which is the same identifier as returned from QObject::startTime...
Definition qcoreevent.h:363
static void setPalette(const QPalette &)
Definition qtooltip.cpp:546
The QTouchEvent class contains parameters that describe a touch event.
Definition qevent.h:916
static void enterWhatsThisMode()
This function switches the user interface into "What's This?" mode.
static int instanceCounter
Definition qwidget_p.h:693
QMap< Qt::GestureType, Qt::GestureFlags > gestureContext
Definition qwidget_p.h:704
static QWidgetMapper * mapper
Definition qwidget_p.h:653
bool stealKeyboardGrab(bool grab)
static void setWidgetParentHelper(QObject *widgetAsObject, QObject *newParent)
bool stealMouseGrab(bool grab)
static int maxInstances
Definition qwidget_p.h:694
static QWidgetSet * allWidgets
Definition qwidget_p.h:654
QWidget * widget() const
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
void setAttribute(Qt::WidgetAttribute, bool on=true)
Sets the attribute attribute on this widget if on is true; otherwise clears the attribute.
QWidget * window() const
Returns the window for this widget, i.e.
Definition qwidget.cpp:4320
WId internalWinId() const
Definition qwidget.h:220
QPointF mapToGlobal(const QPointF &) const
Translates the widget coordinate pos to global screen coordinates.
QRect geometry
the geometry of the widget relative to its parent and excluding the window frame
Definition qwidget.h:106
QLayout * layout() const
Returns the layout manager that is installed on this widget, or \nullptr if no layout manager is inst...
bool isVisibleTo(const QWidget *) const
Returns true if this widget would become visible if ancestor is shown; otherwise returns false.
Definition qwidget.cpp:8689
QPoint pos
the position of the widget within its parent widget
Definition qwidget.h:111
bool close()
Closes this widget.
Definition qwidget.cpp:8608
QFontMetrics fontMetrics() const
Returns the font metrics for the widget's current font.
Definition qwidget.h:847
QWidget * focusWidget() const
Returns the last child of this widget that setFocus had been called on.
Definition qwidget.cpp:6851
QRect rect
the internal geometry of the widget excluding any window frame
Definition qwidget.h:116
void setFocus()
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qwidget.h:423
bool isEnabled() const
Definition qwidget.h:814
void update()
Updates the widget unless updates are disabled or the widget is hidden.
static QWidget * mouseGrabber()
Returns the widget that is currently grabbing the mouse input.
QWindow * windowHandle() const
If this is a native widget, return the associated QWindow.
Definition qwidget.cpp:2490
static QWidget * keyboardGrabber()
Returns the widget that is currently grabbing the keyboard input.
QPointF mapFrom(const QWidget *, const QPointF &) const
Translates the widget coordinate pos from the coordinate system of parent to this widget's coordinate...
Definition qwidget.cpp:4236
WId effectiveWinId() const
Definition qwidget.cpp:2469
Qt::FocusPolicy focusPolicy
the way the widget accepts keyboard focus
Definition qwidget.h:140
QWidget * parentWidget() const
Returns the parent of this widget, or \nullptr if it does not have any parent widget.
Definition qwidget.h:904
QCursor cursor
the cursor shape for this widget
Definition qwidget.h:135
bool isWindow() const
Returns true if the widget is an independent window, otherwise returns false.
Definition qwidget.h:811
Qt::WindowStates windowState() const
Returns the current window state.
Definition qwidget.cpp:2895
bool isAncestorOf(const QWidget *child) const
Returns true if this widget is a parent, (or grandparent and so on to any level), of the given child,...
Definition qwidget.cpp:8868
bool isActiveWindow
whether this widget's window is the active window
Definition qwidget.h:139
QPointF mapToParent(const QPointF &) const
Translates the widget coordinate pos to a coordinate in the parent widget.
Definition qwidget.cpp:4270
bool isVisible() const
Definition qwidget.h:874
QPointF mapFromGlobal(const QPointF &) const
Translates the global screen coordinate pos to widget coordinates.
Qt::WindowType windowType() const
Returns the window type of this widget.
Definition qwidget.h:801
void setCursor(const QCursor &)
Definition qwidget.cpp:4967
bool testAttribute(Qt::WidgetAttribute) const
Returns true if attribute attribute is set on this widget; otherwise returns false.
Definition qwidget.h:910
static QWindowPrivate * get(QWindow *window)
Definition qwindow_p.h:94
bool isPopup() const
Definition qwindow_p.h:88
\inmodule QtGui
Definition qwindow.h:63
QOpenGLWidget * widget
[1]
QHash< int, QWidget * > hash
[35multi]
QString text
bool focus
[0]
double e
QSet< QString >::iterator it
QStyleOptionButton opt
short next
Definition keywords.cpp:445
Combined button and popup list for selecting options.
@ WindowMinimized
Definition qnamespace.h:252
NavigationMode
@ NavigationModeKeypadTabOrder
@ TabFocusAllControls
Definition qnamespace.h:117
@ NoButton
Definition qnamespace.h:56
@ WA_AcceptTouchEvents
Definition qnamespace.h:403
@ WA_UnderMouse
Definition qnamespace.h:283
@ WA_TouchPadAcceptSingleTouchEvents
Definition qnamespace.h:405
@ WA_TransparentForMouseEvents
Definition qnamespace.h:316
@ WA_MacMiniSize
Definition qnamespace.h:362
@ WA_SetLocale
Definition qnamespace.h:357
@ WA_AlwaysShowToolTips
Definition qnamespace.h:353
@ WA_SetCursor
Definition qnamespace.h:304
@ WA_Hover
Definition qnamespace.h:339
@ WA_WState_Polished
Definition qnamespace.h:331
@ WA_DontShowOnScreen
Definition qnamespace.h:382
@ WA_NoMouseReplay
Definition qnamespace.h:319
@ WA_KeyboardFocusChange
Definition qnamespace.h:343
@ WA_SetStyle
Definition qnamespace.h:355
@ WA_NoMousePropagation
Definition qnamespace.h:338
@ WA_WState_AcceptedTouchBeginEvent
Definition qnamespace.h:404
@ WA_WState_Created
Definition qnamespace.h:326
@ WA_MacSmallSize
Definition qnamespace.h:361
@ WA_InputMethodEnabled
Definition qnamespace.h:294
WindowModality
@ ApplicationModal
@ GestureStarted
FocusPolicy
Definition qnamespace.h:105
@ WheelFocus
Definition qnamespace.h:110
@ ClickFocus
Definition qnamespace.h:108
@ NoFocus
Definition qnamespace.h:106
@ TabFocus
Definition qnamespace.h:107
@ StrongFocus
Definition qnamespace.h:109
@ gray
Definition qnamespace.h:32
@ UI_AnimateToolBox
@ UI_FadeMenu
@ UI_AnimateCombo
@ UI_General
@ UI_AnimateTooltip
@ UI_AnimateMenu
@ UI_FadeTooltip
@ Key_Tab
Definition qnamespace.h:659
@ Key_Right
Definition qnamespace.h:674
@ Key_Backtab
Definition qnamespace.h:660
@ Key_Left
Definition qnamespace.h:672
@ Key_Up
Definition qnamespace.h:673
@ Key_Down
Definition qnamespace.h:675
@ NoModifier
@ AA_SetPalette
Definition qnamespace.h:447
@ AA_NativeWindows
Definition qnamespace.h:427
@ CaseInsensitive
GestureType
@ ReceivePartialGestures
ScrollPhase
@ ScrollBegin
@ ScrollUpdate
@ ScrollMomentum
@ NoScrollPhase
@ ScrollEnd
@ Desktop
Definition qnamespace.h:214
@ Popup
Definition qnamespace.h:210
@ Dialog
Definition qnamespace.h:207
@ SubWindow
Definition qnamespace.h:215
FocusReason
@ PopupFocusReason
@ BacktabFocusReason
@ NoFocusReason
@ MouseFocusReason
@ OtherFocusReason
@ ActiveWindowFocusReason
@ TabFocusReason
@ ShortcutFocusReason
QAccessibleInterface * qAccessibleFactory(const QString &classname, QObject *object)
static void * context
Q_CORE_EXPORT void qt_call_post_routines()
static int uiEffectToFlag(Qt::UIEffect effect)
static bool popupGrabOk
bool Q_WIDGETS_EXPORT qt_tab_all_widgets()
static void initResources()
void qt_init_tooltip_palette()
int openPopupCount
bool qt_replay_popup_mouse_event
static void ungrabMouseForPopup(QWidget *popup)
static void ungrabKeyboardForPopup(QWidget *popup)
FontHash * qt_app_fonts_hash()
bool qt_popup_down_closed
Q_WIDGETS_EXPORT bool qt_tryModalHelper(QWidget *widget, QWidget **rettop)
int qt_antialiasing_threshold
bool qt_in_tab_key_event
QWidget * qt_popup_down
QWidget * qt_desktopWidget
Q_WIDGETS_EXPORT QWidget * qt_button_down
void qRegisterWidgetsVariant()
void qt_cleanup()
static void grabForPopup(QWidget *popup)
QPointer< QWidget > qt_last_mouse_receiver
QWidget * qt_tlw_for_window(QWindow *wnd)
Q_GUI_EXPORT bool qt_sendShortcutOverrideEvent(QObject *o, ulong timestamp, int k, Qt::KeyboardModifiers mods, const QString &text=QString(), bool autorep=false, ushort count=1)
bool qt_try_modal(QWidget *widget, QEvent::Type type)
#define qApp
Q_GUI_EXPORT bool qt_is_tty_app
void qt_qpa_set_cursor(QWidget *w, bool force)
Definition qwidget.cpp:5021
#define QByteArrayLiteral(str)
Definition qbytearray.h:52
Q_CORE_EXPORT int qstrcmp(const char *str1, const char *str2)
#define Q_FALLTHROUGH()
#define Q_UNLIKELY(x)
std::pair< T1, T2 > QPair
void Q_CORE_EXPORT qt_call_post_routines()
#define qApp
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage void
static const char help[]
bool qIsInf(qfloat16 f) noexcept
Definition qfloat16.h:237
#define Q_GLOBAL_STATIC(TYPE, NAME,...)
Q_WIDGETS_EXPORT bool qt_tab_all_widgets()
Q_CONSTINIT Q_GUI_EXPORT bool qt_is_tty_app
#define CHECK_QAPP_INSTANCE(...)
#define qDebug
[1]
Definition qlogging.h:160
#define qWarning
Definition qlogging.h:162
GLint GLint GLint GLint GLint x
[0]
GLenum mode
GLuint64 key
GLfloat GLfloat GLfloat w
[0]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLuint GLuint end
GLdouble GLdouble GLdouble GLdouble top
GLenum GLenum GLsizei count
GLenum GLenum GLsizei const GLuint GLboolean enabled
GLfloat GLfloat f
GLsizei GLsizei GLfloat distance
GLenum type
GLenum target
GLboolean enable
GLenum GLuint GLintptr offset
GLboolean GLboolean g
GLuint name
GLint y
struct _cl_event * event
GLuint res
GLuint in
GLuint64EXT * result
[6]
GLdouble s
[6]
Definition qopenglext.h:235
GLfloat GLfloat p
[1]
static void initResources()
Definition qpdf.cpp:38
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
SSL_CTX int(*) void arg)
#define qPrintable(string)
Definition qstring.h:1391
QStyleSheetStyle * qt_styleSheet(QStyle *style)
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
Q_CORE_EXPORT bool qEnvironmentVariableIsSet(const char *varName) noexcept
Q_CORE_EXPORT int qEnvironmentVariableIntValue(const char *varName, bool *ok=nullptr) noexcept
#define emit
#define Q_UNUSED(x)
#define Q_TRACE_METADATA(provider, metadata)
Definition qtrace_p.h:234
#define Q_TRACE_PREFIX(provider, prefix)
Definition qtrace_p.h:233
#define Q_TRACE(x,...)
Definition qtrace_p.h:144
#define Q_TRACE_EXIT(x,...)
Definition qtrace_p.h:145
#define Q_TRACE_POINT(provider, tracepoint,...)
Definition qtrace_p.h:232
#define Q_INIT_RESOURCE(name)
Definition qtresource.h:14
unsigned long ulong
Definition qtypes.h:30
unsigned int uint
Definition qtypes.h:29
unsigned short ushort
Definition qtypes.h:28
double qreal
Definition qtypes.h:92
#define leave(x)
Q_WIDGETS_EXPORT QWidgetPrivate * qt_widget_private(QWidget *widget)
#define QWIDGETSIZE_MAX
Definition qwidget.h:930
QWidget * qobject_cast< QWidget * >(QObject *o)
Definition qwidget.h:786
QT_BEGIN_NAMESPACE typedef QHash< WId, QWidget * > QWidgetMapper
Definition qwindowdefs.h:68
QSet< QWidget * > QWidgetSet
Definition qwindowdefs.h:69
QList< QWidget * > QWidgetList
Definition qwindowdefs.h:47
#define enabled
static QPalette toolTipPalette(const QPalette &systemPalette, bool light)
QPointer< QWindow > qt_last_mouse_receiver
Q_GUI_EXPORT bool qt_sendShortcutOverrideEvent(QObject *o, ulong timestamp, int k, Qt::KeyboardModifiers mods, const QString &text=QString(), bool autorep=false, ushort count=1)
const char className[16]
[1]
Definition qwizard.cpp:100
QList< int > list
[14]
QTextStream out(stdout)
[7]
QList< QWidget * > widgets
[11]
QVBoxLayout * layout
QGraphicsOpacityEffect * effect
the effect attached to this item
QGraphicsScene scene
[0]
QLayoutItem * child
[0]
aWidget window() -> setWindowTitle("New Window Title")
[2]
QSizePolicy policy
\inmodule QtCore
const char * className() const
Returns the class name.
const QMetaObject * superClass() const
Returns the meta-object of the superclass, or \nullptr if there is no such object.
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent