Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qapplication.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
149
295{
297 if (const QWidgetWindow *widgetWindow = qobject_cast<const QWidgetWindow *>(window))
298 return widgetWindow->widget();
299 }
300 return nullptr;
301}
302
313
314QStyle *QApplicationPrivate::app_style = nullptr; // default application style
315#ifndef QT_NO_STYLE_STYLESHEET
316QString QApplicationPrivate::styleSheet; // default application stylesheet
317#endif
318QPointer<QWidget> QApplicationPrivate::leaveAfterRelease = nullptr;
319
320QFont *QApplicationPrivate::sys_font = nullptr; // default system font
321QFont *QApplicationPrivate::set_font = nullptr; // default font set by programmer
322
323QWidget *QApplicationPrivate::main_widget = nullptr; // main application widget
324QWidget *QApplicationPrivate::focus_widget = nullptr; // has keyboard input focus
325QWidget *QApplicationPrivate::hidden_focus_widget = nullptr; // will get keyboard input focus after show()
326QWidget *QApplicationPrivate::active_window = nullptr; // toplevel with keyboard focus
327#if QT_CONFIG(wheelevent)
328QPointer<QWidget> QApplicationPrivate::wheel_widget;
329#endif
334#ifdef QT_KEYPAD_NAVIGATION
335Qt::NavigationMode QApplicationPrivate::navigationMode = Qt::NavigationModeKeypadTabOrder;
336QWidget *QApplicationPrivate::oldEditFocus = nullptr;
337#endif
338
339inline bool QApplicationPrivate::isAlien(QWidget *widget)
340{
341 return widget && !widget->isWindow();
342}
343
344bool Q_WIDGETS_EXPORT qt_tab_all_widgets()
345{
346 return QGuiApplication::styleHints()->tabFocusBehavior() == Qt::TabFocusAllControls;
347}
348
349// ######## move to QApplicationPrivate
350// Default fonts (per widget type)
351Q_GLOBAL_STATIC(FontHash, app_fonts)
352// Exported accessor for use outside of this file
353FontHash *qt_app_fonts_hash() { return app_fonts(); }
354
355QWidgetList *QApplicationPrivate::popupWidgets = nullptr; // has keyboard input focus
356
357QWidget *qt_desktopWidget = nullptr; // root window widgets
358
363{
364 if (styleOverride.isEmpty() && qEnvironmentVariableIsSet("QT_STYLE_OVERRIDE"))
365 styleOverride = QString::fromLocal8Bit(qgetenv("QT_STYLE_OVERRIDE"));
366
367 // process platform-indep command line
368 if (qt_is_tty_app || !argc)
369 return;
370
371 int i, j;
372
373 j = 1;
374 for (i=1; i<argc; i++) { // if you add anything here, modify QCoreApplication::arguments()
375 if (!argv[i])
376 continue;
377 if (*argv[i] != '-') {
378 argv[j++] = argv[i];
379 continue;
380 }
381 const char *arg = argv[i];
382 if (arg[1] == '-') // startsWith("--")
383 ++arg;
384 if (strcmp(arg, "-qdevel") == 0 || strcmp(arg, "-qdebug") == 0) {
385 // obsolete argument
386#ifndef QT_NO_STYLE_STYLESHEET
387 } else if (strcmp(arg, "-stylesheet") == 0 && i < argc -1) {
388 styleSheet = "file:///"_L1;
390 } else if (strncmp(arg, "-stylesheet=", 12) == 0) {
391 styleSheet = "file:///"_L1;
393#endif
394 } else if (qstrcmp(arg, "-widgetcount") == 0) {
395 widgetCount = true;
396 } else {
397 argv[j++] = argv[i];
398 }
399 }
400
401 if (j < argc) {
402 argv[j] = nullptr;
403 argc = j;
404 }
405}
406
452#ifdef Q_QDOC
453QApplication::QApplication(int &argc, char **argv)
454#else
455QApplication::QApplication(int &argc, char **argv, int)
456#endif
457 : QGuiApplication(*new QApplicationPrivate(argc, argv))
458{
459 Q_D(QApplication);
460 d->init();
461}
462
467{
468#if defined(Q_OS_MACOS)
470#endif
471
473
475
478
479 // Must be called before initialize()
484
485 initialize();
486 eventDispatcher->startingUp();
487
488#if QT_CONFIG(accessibility)
489 // factory for accessible interfaces for widgets shipped with Qt
490 QAccessible::installFactory(&qAccessibleFactory);
491#endif
492
493}
494
496{
497#if QT_CONFIG(tooltip)
499 QPalette toolTipPal = *toolTipPalette;
500 toolTipPal.setResolveMask(0);
501 QToolTip::setPalette(toolTipPal);
502 }
503#endif
504}
505
506extern void qRegisterWidgetsVariant();
507
512{
513 is_app_running = false; // Starting up.
514
517
518 // needed for a static build.
520
521 // needed for widgets in QML
523
525 if (!styleOverride.isEmpty()) {
526 if (auto *style = QStyleFactory::create(styleOverride.toLower())) {
528 } else {
529 qWarning("QApplication: invalid style override '%s' passed, ignoring it.\n"
530 "\tAvailable styles: %s", qPrintable(styleOverride),
531 qPrintable(QStyleFactory::keys().join(", "_L1)));
532 // Clear styleOverride so it is not picked by Qt Quick Controls (QTBUG-100563)
533 styleOverride.clear();
534 }
535 }
536
537 // Trigger default style if none was set already
539 }
540
541 if (qEnvironmentVariableIntValue("QT_USE_NATIVE_WINDOWS") > 0)
543
544 if (!qt_is_tty_app)
546
550 }
551
552 is_app_running = true; // no longer starting up
553}
554
556{
558 if (!theme)
559 return;
560 FontHash *fontHash = app_fonts();
561 fontHash->clear();
562
563 if (const QFont *font = theme->font(QPlatformTheme::MenuFont))
564 fontHash->insert(QByteArrayLiteral("QMenu"), *font);
565 if (const QFont *font = theme->font(QPlatformTheme::MenuBarFont))
566 fontHash->insert(QByteArrayLiteral("QMenuBar"), *font);
567 if (const QFont *font = theme->font(QPlatformTheme::MenuItemFont))
568 fontHash->insert(QByteArrayLiteral("QMenuItem"), *font);
569 if (const QFont *font = theme->font(QPlatformTheme::MessageBoxFont))
570 fontHash->insert(QByteArrayLiteral("QMessageBox"), *font);
571 if (const QFont *font = theme->font(QPlatformTheme::LabelFont))
572 fontHash->insert(QByteArrayLiteral("QLabel"), *font);
573 if (const QFont *font = theme->font(QPlatformTheme::TipLabelFont))
574 fontHash->insert(QByteArrayLiteral("QTipLabel"), *font);
575 if (const QFont *font = theme->font(QPlatformTheme::TitleBarFont))
576 fontHash->insert(QByteArrayLiteral("QTitleBar"), *font);
577 if (const QFont *font = theme->font(QPlatformTheme::StatusBarFont))
578 fontHash->insert(QByteArrayLiteral("QStatusBar"), *font);
580 fontHash->insert(QByteArrayLiteral("QMdiSubWindowTitleBar"), *font);
582 fontHash->insert(QByteArrayLiteral("QDockWidgetTitle"), *font);
583 if (const QFont *font = theme->font(QPlatformTheme::PushButtonFont))
584 fontHash->insert(QByteArrayLiteral("QPushButton"), *font);
585 if (const QFont *font = theme->font(QPlatformTheme::CheckBoxFont))
586 fontHash->insert(QByteArrayLiteral("QCheckBox"), *font);
587 if (const QFont *font = theme->font(QPlatformTheme::RadioButtonFont))
588 fontHash->insert(QByteArrayLiteral("QRadioButton"), *font);
589 if (const QFont *font = theme->font(QPlatformTheme::ToolButtonFont))
590 fontHash->insert(QByteArrayLiteral("QToolButton"), *font);
591 if (const QFont *font = theme->font(QPlatformTheme::ItemViewFont))
592 fontHash->insert(QByteArrayLiteral("QAbstractItemView"), *font);
593 if (const QFont *font = theme->font(QPlatformTheme::ListViewFont))
594 fontHash->insert(QByteArrayLiteral("QListView"), *font);
595 if (const QFont *font = theme->font(QPlatformTheme::HeaderViewFont))
596 fontHash->insert(QByteArrayLiteral("QHeaderView"), *font);
597 if (const QFont *font = theme->font(QPlatformTheme::ListBoxFont))
598 fontHash->insert(QByteArrayLiteral("QListBox"), *font);
600 fontHash->insert(QByteArrayLiteral("QComboMenuItem"), *font);
602 fontHash->insert(QByteArrayLiteral("QComboLineEdit"), *font);
603 if (const QFont *font = theme->font(QPlatformTheme::SmallFont))
604 fontHash->insert(QByteArrayLiteral("QSmallFont"), *font);
605 if (const QFont *font = theme->font(QPlatformTheme::MiniFont))
606 fontHash->insert(QByteArrayLiteral("QMiniFont"), *font);
607}
608
609/*****************************************************************************
610 Functions returning the active popup and modal widgets.
611 *****************************************************************************/
612
633
634
650{
651 QWidgetWindow *widgetWindow = qobject_cast<QWidgetWindow *>(modalWindow());
652 return widgetWindow ? widgetWindow->widget() : nullptr;
653}
654
661{
662 Q_D(QApplication);
663
664 //### this should probable be done even later
666
667 // kill timers before closing down the dispatcher
668 d->toolTipWakeUp.stop();
669 d->toolTipFallAsleep.stop();
670
673
675 QWidgetPrivate::mapper = nullptr;
676
677 // delete all widgets
681 for (QWidgetSet::ConstIterator it = mySet->constBegin(), cend = mySet->constEnd(); it != cend; ++it) {
682 QWidget *w = *it;
683 if (!w->parent()) // window
684 w->destroy(true, true);
685 }
686 delete mySet;
687 }
688
689 delete qt_desktopWidget;
690 qt_desktopWidget = nullptr;
691
693
698 app_fonts()->clear();
699
702
703#if QT_CONFIG(draganddrop)
704 if (!qt_is_tty_app)
705 delete QDragManager::self();
706#endif
707
708 d->cleanupMultitouch();
709
712
713 QApplicationPrivate::active_window = nullptr; //### this should not be necessary
714
716 qDebug("Widgets left: %i Max widgets: %i \n", QWidgetPrivate::instanceCounter, QWidgetPrivate::maxInstances);
717
719
722}
723
735{
737 if (!window)
738 return nullptr;
739
740 QWidget *child = nullptr;
741
742 if (!window->testAttribute(Qt::WA_TransparentForMouseEvents))
743 child = window->childAt(window->mapFromGlobal(p));
744
745 if (child)
746 return child;
747
748 if (window->testAttribute(Qt::WA_TransparentForMouseEvents)) {
749 //shoot a hole in the widget and try once again,
750 //suboptimal on Qt for Embedded Linux where we do
751 //know the stacking order of the toplevels.
752 int x = p.x();
753 int y = p.y();
754 QRegion oldmask = window->mask();
755 QPoint wpoint = window->mapFromGlobal(QPoint(x, y));
756 QRegion newmask = (oldmask.isEmpty() ? QRegion(window->rect()) : oldmask)
757 - QRegion(wpoint.x(), wpoint.y(), 1, 1);
758 window->setMask(newmask);
759 QWidget *recurse = nullptr;
760 if (QApplication::topLevelAt(p) != window) // verify recursion will terminate
761 recurse = widgetAt(x, y);
762 if (oldmask.isEmpty())
763 window->clearMask();
764 else
765 window->setMask(oldmask);
766 return recurse;
767 }
768 return window;
769}
770
784{
785 // Only compress the following events:
786 const QEvent::Type type = event->type();
787 switch (type) {
791 case QEvent::Resize:
792 case QEvent::Move:
794 break;
795 default:
796 return QGuiApplication::compressEvent(event, receiver, postedEvents);
797 }
798
799 for (const auto &postedEvent : std::as_const(*postedEvents)) {
800
801 // Continue, unless a valid event of the same type exists for the same receiver
802 if (postedEvent.receiver != receiver
803 || !postedEvent.event
804 || postedEvent.event->type() != type) {
805 continue;
806 }
807
808 // Handle type specific compression
809 switch (type) {
810 case QEvent::Resize:
811 static_cast<QResizeEvent *>(postedEvent.event)->m_size =
812 static_cast<const QResizeEvent *>(event)->size();
813 break;
814 case QEvent::Move:
815 static_cast<QMoveEvent *>(postedEvent.event)->m_pos =
816 static_cast<const QMoveEvent *>(event)->pos();
817 break;
819 static_cast<QUpdateLaterEvent *>(postedEvent.event)->m_region +=
820 static_cast<const QUpdateLaterEvent *>(event)->region();
821 break;
825 break;
826 default:
827 continue;
828 }
829 delete event;
830 return true;
831 }
832 return false;
833}
834
865
870
871#ifndef QT_NO_STYLE_STYLESHEET
872
877
879{
882 if (styleSheet.isEmpty()) { // application style sheet removed
883 if (!styleSheetStyle)
884 return; // there was no stylesheet before
885 setStyle(styleSheetStyle->base);
886 } else if (styleSheetStyle) { // style sheet update, just repolish
887 styleSheetStyle->repolish(qApp);
888 } else { // stylesheet set the first time
890 QApplicationPrivate::app_style->setParent(newStyleSheetStyle);
891 setStyle(newStyleSheetStyle);
892 }
893}
894
895#endif // QT_NO_STYLE_STYLESHEET
896
903{
905 // Create default style
906 if (!qobject_cast<QApplication *>(QCoreApplication::instance())) {
907 Q_ASSERT(!"No style available without QApplication!");
908 return nullptr;
909 }
910
911 auto &defaultStyle = QApplicationPrivate::app_style;
912
914 if (!defaultStyle) {
915 const QStringList styles = QStyleFactory::keys();
916 for (const auto &style : styles) {
917 if ((defaultStyle = QStyleFactory::create(style)))
918 break;
919 }
920 }
921 if (!defaultStyle) {
922 Q_ASSERT(!"No styles available!");
923 return nullptr;
924 }
925
926 // Take ownership of the style
927 defaultStyle->setParent(qApp);
928
930
931#ifndef QT_NO_STYLE_STYLESHEET
932 if (!QApplicationPrivate::styleSheet.isEmpty()) {
934 } else
935#endif
936 {
937 defaultStyle->polish(qApp);
938 }
939 }
940
942}
943
967{
969 return;
970
971 QWidgetList all = allWidgets();
972
973 // clean up the old style
976 for (QWidgetList::ConstIterator it = all.constBegin(), cend = all.constEnd(); it != cend; ++it) {
977 QWidget *w = *it;
978 if (!(w->windowType() == Qt::Desktop) && // except desktop
979 w->testAttribute(Qt::WA_WState_Polished)) { // has been polished
981 }
982 }
983 }
985 }
986
988
989#ifndef QT_NO_STYLE_STYLESHEET
991 // we have a stylesheet already and a new style is being set
992 QStyleSheetStyle *newStyleSheetStyle = new QStyleSheetStyle(style);
993 style->setParent(newStyleSheetStyle);
994 QApplicationPrivate::app_style = newStyleSheetStyle;
995 } else
996#endif // QT_NO_STYLE_STYLESHEET
998 QApplicationPrivate::app_style->setParent(qApp); // take ownership
999
1000 // Take care of possible palette requirements of certain
1001 // styles. Do it before polishing the application since the
1002 // style might call QApplication::setPalette() itself.
1004
1005 // The default widget font hash is based on the platform theme,
1006 // not the style, but the widget fonts could in theory have been
1007 // affected by polish of the previous style, without a proper
1008 // cleanup in unpolish, so reset it now before polishing the
1009 // new style.
1011
1012 // initialize the application with the new style
1014
1015 // re-polish existing widgets if necessary
1017 for (QWidgetList::ConstIterator it = all.constBegin(), cend = all.constEnd(); it != cend; ++it) {
1018 QWidget *w = *it;
1019 if (w->windowType() != Qt::Desktop && w->testAttribute(Qt::WA_WState_Polished)) {
1020 if (w->style() == QApplicationPrivate::app_style)
1021 QApplicationPrivate::app_style->polish(w); // repolish
1022#ifndef QT_NO_STYLE_STYLESHEET
1023 else
1024 w->setStyleSheet(w->styleSheet()); // touch
1025#endif
1026 }
1027 }
1028
1029 for (QWidgetList::ConstIterator it = all.constBegin(), cend = all.constEnd(); it != cend; ++it) {
1030 QWidget *w = *it;
1031 if (w->windowType() != Qt::Desktop && !w->testAttribute(Qt::WA_SetStyle)) {
1034 w->update();
1035 }
1036 }
1037 }
1038
1039#ifndef QT_NO_STYLE_STYLESHEET
1040 if (QStyleSheetStyle *oldStyleSheetStyle = qt_styleSheet(old)) {
1041 oldStyleSheetStyle->deref();
1042 } else
1043#endif
1044 if (old && old->parent() == qApp) {
1045 delete old;
1046 }
1047
1052 }
1053}
1054
1072{
1074 if (!s)
1075 return nullptr;
1076
1077 setStyle(s);
1078 return s;
1079}
1080
1081// Widget specific palettes
1083
1085{
1086 // Start out with a palette based on the style, in case there's no theme
1087 // available, or so that we can fill in missing roles in the theme.
1088 QPalette palette = app_style ? app_style->standardPalette() : Qt::gray;
1089
1090 // Prefer theme palette if available, but fill in missing roles from style
1091 // for compatibility. Note that the style's standard palette is not prioritized
1092 // over the theme palette, as the documented way of applying the style's palette
1093 // is to set it explicitly using QApplication::setPalette().
1094 if (const QPalette *themePalette = platformTheme() ? platformTheme()->palette() : nullptr)
1095 palette = themePalette->resolve(palette);
1096
1097 // This palette now is Qt-generated, so reset the resolve mask. This allows
1098 // QStyle::polish implementations to respect palettes that are user provided,
1099 // by checking if the palette has a brush set for a color that the style might
1100 // otherwise overwrite.
1101 palette.setResolveMask(0);
1102
1103 // Finish off by letting the application style polish the palette. This will
1104 // not result in the polished palette becoming a user-set palette, as the
1105 // resulting base palette is only used as a fallback, with the resolve mask
1106 // set to 0.
1107 if (app_style)
1108 app_style->polish(palette);
1109
1110 return palette;
1111}
1112
1125{
1126 auto &widgetPalettes = QApplicationPrivate::widgetPalettes;
1127 if (w && !widgetPalettes.isEmpty()) {
1128 auto it = widgetPalettes.constFind(w->metaObject()->className());
1129 const auto cend = widgetPalettes.constEnd();
1130 if (it != cend)
1131 return *it;
1132 for (it = widgetPalettes.constBegin(); it != cend; ++it) {
1133 if (w->inherits(it.key()))
1134 return it.value();
1135 }
1136 }
1137 return palette();
1138}
1139
1148{
1149 auto &widgetPalettes = QApplicationPrivate::widgetPalettes;
1150 if (className && !widgetPalettes.isEmpty()) {
1151 auto it = widgetPalettes.constFind(className);
1152 if (it != widgetPalettes.constEnd())
1153 return *it;
1154 }
1155
1156 return QGuiApplication::palette();
1157}
1158
1182{
1183 if (className) {
1184 QPalette polishedPalette = palette;
1186 auto originalResolveMask = palette.resolveMask();
1187 QApplicationPrivate::app_style->polish(polishedPalette);
1188 polishedPalette.setResolveMask(originalResolveMask);
1189 }
1190
1191 QApplicationPrivate::widgetPalettes.insert(className, polishedPalette);
1192 if (qApp)
1193 qApp->d_func()->handlePaletteChanged(className);
1194 } else {
1196 }
1197}
1198
1200{
1202 return;
1203
1204 // Setting the global application palette is documented to
1205 // reset any previously set class specific widget palettes.
1206 if (!className && !widgetPalettes.isEmpty())
1207 widgetPalettes.clear();
1208
1210
1213 for (auto widget : widgets) {
1216 }
1217
1218#if QT_CONFIG(graphicsview)
1219 for (auto scene : std::as_const(scene_list))
1221#endif
1222
1223 // Palette has been reset back to the default application palette,
1224 // so we need to reinitialize the widget palettes from the theme.
1227}
1228
1230{
1232 if (!platformTheme)
1233 return;
1234
1235 widgetPalettes.clear();
1236
1237 struct ThemedWidget { const char *className; QPlatformTheme::Palette palette; };
1238
1239 static const ThemedWidget themedWidgets[] = {
1240 { "QToolButton", QPlatformTheme::ToolButtonPalette },
1241 { "QAbstractButton", QPlatformTheme::ButtonPalette },
1242 { "QCheckBox", QPlatformTheme::CheckBoxPalette },
1243 { "QRadioButton", QPlatformTheme::RadioButtonPalette },
1244 { "QHeaderView", QPlatformTheme::HeaderPalette },
1245 { "QAbstractItemView", QPlatformTheme::ItemViewPalette },
1246 { "QMessageBoxLabel", QPlatformTheme::MessageBoxLabelPalette },
1247 { "QTabBar", QPlatformTheme::TabBarPalette },
1248 { "QLabel", QPlatformTheme::LabelPalette },
1249 { "QGroupBox", QPlatformTheme::GroupBoxPalette },
1250 { "QMenu", QPlatformTheme::MenuPalette },
1251 { "QMenuBar", QPlatformTheme::MenuBarPalette },
1252 { "QTextEdit", QPlatformTheme::TextEditPalette },
1253 { "QTextControl", QPlatformTheme::TextEditPalette },
1254 { "QLineEdit", QPlatformTheme::TextLineEditPalette },
1255 };
1256
1257 for (const auto themedWidget : themedWidgets) {
1258 if (auto *palette = platformTheme->palette(themedWidget.palette))
1259 QApplication::setPalette(*palette, themedWidget.className);
1260 }
1261}
1262
1272
1284{
1285 typedef FontHash::const_iterator FontHashConstIt;
1286
1287 FontHash *hash = app_fonts();
1288
1289 if (widget && hash && hash->size()) {
1290#ifdef Q_OS_MAC
1291 // short circuit for small and mini controls
1293 return hash->value(QByteArrayLiteral("QSmallFont"));
1295 return hash->value(QByteArrayLiteral("QMiniFont"));
1296 }
1297#endif
1298 // Return the font for the nearest registered superclass
1299 const QMetaObject *metaObj = widget->metaObject();
1300 FontHashConstIt it = hash->constFind(metaObj->className());
1301 const FontHashConstIt cend = hash->constEnd();
1302 while (it == cend && metaObj != &QWidget::staticMetaObject) {
1303 metaObj = metaObj->superClass();
1304 it = hash->constFind(metaObj->className());
1305 }
1306 if (it != cend)
1307 return it.value();
1308 }
1309 return font();
1310}
1311
1320{
1321 FontHash *hash = app_fonts();
1322 if (className && hash && hash->size()) {
1324 if (it != hash->constEnd())
1325 return *it;
1326 }
1327 return font();
1328}
1329
1330
1351{
1352 FontHash *hash = app_fonts();
1353 if (!className) {
1355 if (hash && hash->size())
1356 hash->clear();
1357 } else if (hash) {
1358 hash->insert(className, font);
1359 }
1363 for (QWidgetList::ConstIterator it = wids.constBegin(), cend = wids.constEnd(); it != cend; ++it) {
1364 QWidget *w = *it;
1365 if (!w->isWindow() && w->inherits(className)) // matching class
1366 sendEvent(w, &e);
1367 }
1368
1369#if QT_CONFIG(graphicsview)
1370 // Send to all scenes as well.
1371 QList<QGraphicsScene *> &scenes = qApp->d_func()->scene_list;
1373 it != scenes.constEnd(); ++it) {
1375 }
1376#endif // QT_CONFIG(graphicsview)
1377 }
1381 else
1383 }
1384}
1385
1389{
1390 if (!sys_font)
1391 sys_font = new QFont(font);
1392 else
1393 *sys_font = font;
1394
1397}
1398
1402{
1403#if defined(QT_BUILD_INTERNAL)
1404 // Allow auto-tests to override the desktop style
1405 if (qEnvironmentVariableIsSet("QT_DESKTOP_STYLE_KEY"))
1406 return QString::fromLocal8Bit(qgetenv("QT_DESKTOP_STYLE_KEY"));
1407#endif
1408
1409 // The platform theme might return a style that is not available, find
1410 // first valid one.
1412 const QStringList availableKeys = QStyleFactory::keys();
1413 const auto styles = theme->themeHint(QPlatformTheme::StyleNames).toStringList();
1414 for (const QString &style : styles) {
1415 if (availableKeys.contains(style, Qt::CaseInsensitive))
1416 return style;
1417 }
1418 }
1419 return QString();
1420}
1421
1423{
1427
1428 // send to all top-level QWidgets
1429 for (auto *w : list) {
1430 windowList.removeOne(w->windowHandle());
1432 }
1433
1434 // in case there are any plain QWindows in this QApplication-using
1435 // application, also send the notification to them
1436 for (int i = 0; i < windowList.size(); ++i)
1437 QCoreApplication::sendEvent(windowList.at(i), &ev);
1438}
1439
1453{
1455 if (QWidgetPrivate::allWidgets != nullptr) {
1456 const auto isTopLevelWidget = [] (const QWidget *w) {
1457 return w->isWindow() && w->windowType() != Qt::Desktop;
1458 };
1459 std::copy_if(QWidgetPrivate::allWidgets->cbegin(), QWidgetPrivate::allWidgets->cend(),
1460 std::back_inserter(list), isTopLevelWidget);
1461 }
1462 return list;
1463}
1464
1484
1496
1498{
1499#if QT_CONFIG(graphicsview)
1500 if (focus && focus->window()->graphicsProxyWidget())
1501 return;
1502#endif
1503
1504 hidden_focus_widget = nullptr;
1505
1506 if (focus != focus_widget) {
1507 if (focus && focus->isHidden()) {
1509 return;
1510 }
1511
1512 if (focus && (reason == Qt::BacktabFocusReason || reason == Qt::TabFocusReason)
1514 focus->window()->setAttribute(Qt::WA_KeyboardFocusChange);
1515 else if (focus && reason == Qt::ShortcutFocusReason) {
1516 focus->window()->setAttribute(Qt::WA_KeyboardFocusChange);
1517 }
1518 QWidget *prev = focus_widget;
1520
1521 if (focus_widget)
1522 focus_widget->d_func()->setFocus_sys();
1523
1524 if (reason != Qt::NoFocusReason) {
1525
1526 //send events
1527 if (prev) {
1528#ifdef QT_KEYPAD_NAVIGATION
1529 if (QApplicationPrivate::keyboardNavigationEnabled()) {
1530 if (prev->hasEditFocus() && reason != Qt::PopupFocusReason)
1531 prev->setEditFocus(false);
1532 }
1533#endif
1535 QPointer<QWidget> that = prev;
1537 if (that)
1538 QCoreApplication::sendEvent(that->style(), &out);
1539 }
1542 QPointer<QWidget> that = focus;
1544 if (that)
1545 QCoreApplication::sendEvent(that->style(), &in);
1546 }
1547 emit qApp->focusChanged(prev, focus_widget);
1548 }
1549 }
1550}
1551
1552
1563{
1564 return QApplicationPrivate::active_window;
1565}
1566
1567#if QT_DEPRECATED_SINCE(6,0)
1575QFontMetrics QApplication::fontMetrics()
1576{
1577 return QApplicationPrivate::desktop()->fontMetrics();
1578}
1579#endif
1580
1581bool QApplicationPrivate::tryCloseAllWidgetWindows(QWindowList *processedWindows)
1582{
1583 Q_ASSERT(processedWindows);
1585 if (!w->isVisible() || w->data->is_closing)
1586 break;
1587 QWindow *window = w->windowHandle();
1588 if (!window->close()) // Qt::WA_DeleteOnClose may cause deletion.
1589 return false;
1590 if (window)
1591 processedWindows->append(window);
1592 }
1593
1594retry:
1596 for (auto *w : list) {
1597 if (w->isVisible() && w->windowType() != Qt::Desktop &&
1598 !w->testAttribute(Qt::WA_DontShowOnScreen) && !w->data->is_closing) {
1599 QWindow *window = w->windowHandle();
1600 if (!window->close()) // Qt::WA_DeleteOnClose may cause deletion.
1601 return false;
1602 if (window)
1603 processedWindows->append(window);
1604 goto retry;
1605 }
1606 }
1607 return true;
1608}
1609
1627{
1628 QWindowList processedWindows;
1629 QApplicationPrivate::tryCloseAllWidgetWindows(&processedWindows);
1630}
1631
1642{
1643#if QT_CONFIG(messagebox)
1645#endif // QT_CONFIG(messagebox)
1646}
1647
1667{
1668 Q_D(QApplication);
1669 switch (e->type()) {
1670 case QEvent::Quit:
1671 // FIXME: This logic first tries to close all windows, and then
1672 // checks whether it was successful, but the conditions used in
1673 // closeAllWindows() differ from the verification logic below.
1674 // We should build on the logic in tryCloseAllWidgetWindows().
1676 for (auto *w : topLevelWidgets()) {
1677 if (w->data->is_closing)
1678 continue;
1679 if (w->isVisible() && !(w->windowType() == Qt::Desktop) && !(w->windowType() == Qt::Popup) &&
1680 (!(w->windowType() == Qt::Dialog) || !w->parentWidget()) && !w->testAttribute(Qt::WA_DontShowOnScreen)) {
1681 e->ignore();
1682 return true;
1683 }
1684 }
1685 // Explicitly call QCoreApplication instead of QGuiApplication so that
1686 // we don't let QGuiApplication close any windows we skipped earlier in
1687 // closeAllWindows(). FIXME: Unify all this close magic through closeAllWindows.
1688 return QCoreApplication::event(e);
1689#ifndef Q_OS_WIN
1690 case QEvent::LocaleChange: {
1691 // on Windows the event propagation is taken care by the
1692 // WM_SETTINGCHANGE event handler.
1694 for (auto *w : list) {
1695 if (!(w->windowType() == Qt::Desktop)) {
1696 if (!w->testAttribute(Qt::WA_SetLocale))
1697 w->d_func()->setLocale_helper(QLocale(), true);
1698 }
1699 }
1700 break;
1701 }
1702#endif
1703 case QEvent::Timer: {
1704 QTimerEvent *te = static_cast<QTimerEvent*>(e);
1705 Q_ASSERT(te != nullptr);
1706 if (te->timerId() == d->toolTipWakeUp.timerId()) {
1707 d->toolTipWakeUp.stop();
1708 if (d->toolTipWidget) {
1709 QWidget *w = d->toolTipWidget->window();
1710 // show tooltip if WA_AlwaysShowToolTips is set, or if
1711 // any ancestor of d->toolTipWidget is the active
1712 // window
1713 bool showToolTip = w->testAttribute(Qt::WA_AlwaysShowToolTips);
1714 while (w && !showToolTip) {
1715 showToolTip = w->isActiveWindow();
1716 w = w->parentWidget();
1717 w = w ? w->window() : nullptr;
1718 }
1719 if (showToolTip) {
1720 QHelpEvent e(QEvent::ToolTip, d->toolTipPos, d->toolTipGlobalPos);
1721 QCoreApplication::sendEvent(d->toolTipWidget, &e);
1722 if (e.isAccepted()) {
1723 QStyle *s = d->toolTipWidget->style();
1724 int sleepDelay = s->styleHint(QStyle::SH_ToolTip_FallAsleepDelay, nullptr, d->toolTipWidget, nullptr);
1725 d->toolTipFallAsleep.start(sleepDelay, this);
1726 }
1727 }
1728 }
1729 } else if (te->timerId() == d->toolTipFallAsleep.timerId()) {
1730 d->toolTipFallAsleep.stop();
1731 }
1732 break;
1733 }
1734#if QT_CONFIG(whatsthis)
1737 return true;
1738#endif
1742 // QGuiApplication::event does not account for the cases where
1743 // there is a top level widget without a window handle. So they
1744 // need to have the event posted here
1746 for (auto *w : list) {
1747 if (!w->windowHandle() && (w->windowType() != Qt::Desktop))
1748 postEvent(w, new QEvent(e->type()));
1749 }
1750 break;
1751 }
1752 default:
1753 break;
1754 }
1755
1756 return QGuiApplication::event(e);
1757}
1758
1759// ### FIXME: topLevelWindows does not contain QWidgets without a parent
1760// until QWidgetPrivate::create is called. So we have to override the
1761// QGuiApplication::notifyLayoutDirectionChange
1762// to do the right thing.
1764{
1767
1768 // send to all top-level QWidgets
1769 for (auto *w : list) {
1770 windowList.removeAll(w->windowHandle());
1773 }
1774
1775 // in case there are any plain QWindows in this QApplication-using
1776 // application, also send the notification to them
1777 for (int i = 0; i < windowList.size(); ++i) {
1779 QCoreApplication::sendEvent(windowList.at(i), &ev);
1780 }
1781}
1782
1802#if QT_DEPRECATED_SINCE(6,5)
1803void QApplication::setActiveWindow(QWidget* act)
1804{
1806}
1807#endif
1808
1810{
1811 QWidget* window = act?act->window():nullptr;
1812
1813 if (QApplicationPrivate::active_window == window)
1814 return;
1815
1816#if QT_CONFIG(graphicsview)
1817 if (window && window->graphicsProxyWidget()) {
1818 // Activate the proxy's view->viewport() ?
1819 return;
1820 }
1821#endif
1822
1823 QWidgetList toBeActivated;
1824 QWidgetList toBeDeactivated;
1825
1826 if (QApplicationPrivate::active_window) {
1827 if (QApplication::style()->styleHint(QStyle::SH_Widget_ShareActivation, nullptr, QApplicationPrivate::active_window)) {
1829 for (auto *w : list) {
1830 if (w->isVisible() && w->isActiveWindow())
1831 toBeDeactivated.append(w);
1832 }
1833 } else {
1834 toBeDeactivated.append(QApplicationPrivate::active_window);
1835 }
1836 }
1837
1840 QGuiApplication::inputMethod()->commit();
1841
1844 }
1845
1846 QApplicationPrivate::active_window = window;
1847
1848 if (QApplicationPrivate::active_window) {
1849 if (QApplication::style()->styleHint(QStyle::SH_Widget_ShareActivation, nullptr, QApplicationPrivate::active_window)) {
1851 for (auto *w : list) {
1852 if (w->isVisible() && w->isActiveWindow())
1853 toBeActivated.append(w);
1854 }
1855 } else {
1856 toBeActivated.append(QApplicationPrivate::active_window);
1857 }
1858
1859 }
1860
1861 // first the activation/deactivation events
1862 QEvent activationChange(QEvent::ActivationChange);
1863 QEvent windowActivate(QEvent::WindowActivate);
1864 QEvent windowDeactivate(QEvent::WindowDeactivate);
1865
1866 for (int i = 0; i < toBeActivated.size(); ++i) {
1867 QWidget *w = toBeActivated.at(i);
1868 QApplication::sendSpontaneousEvent(w, &windowActivate);
1869 QApplication::sendSpontaneousEvent(w, &activationChange);
1870 }
1871
1872 for(int i = 0; i < toBeDeactivated.size(); ++i) {
1873 QWidget *w = toBeDeactivated.at(i);
1874 QApplication::sendSpontaneousEvent(w, &windowDeactivate);
1875 QApplication::sendSpontaneousEvent(w, &activationChange);
1876 }
1877
1878 if (QApplicationPrivate::popupWidgets == nullptr) { // !inPopupMode()
1879 // then focus events
1880 if (!QApplicationPrivate::active_window && QApplicationPrivate::focus_widget) {
1882 } else if (QApplicationPrivate::active_window) {
1883 QWidget *w = QApplicationPrivate::active_window->focusWidget();
1884 if (w && w->isVisible() /*&& w->focusPolicy() != QWidget::NoFocus*/)
1885 w->setFocus(Qt::ActiveWindowFocusReason);
1886 else {
1887 w = QApplicationPrivate::focusNextPrevChild_helper(QApplicationPrivate::active_window, true);
1888 if (w) {
1889 w->setFocus(Qt::ActiveWindowFocusReason);
1890 } else {
1892 if (!w && QApplicationPrivate::active_window->focusPolicy() != Qt::NoFocus) {
1893 QApplicationPrivate::active_window->setFocus(Qt::ActiveWindowFocusReason);
1894 } else if (!QApplicationPrivate::active_window->isAncestorOf(w)) {
1895 // If the focus widget is not in the activate_window, clear the focus
1897 }
1898 }
1899 }
1900 }
1901 }
1902}
1903
1905{
1906 // QTBUG-32177, wnd might be a QQuickView embedded via window container.
1907 while (wnd && !wnd->isTopLevel()) {
1908 QWindow *parent = wnd->parent();
1909 if (!parent)
1910 break;
1911
1912 // Don't end up in windows not belonging to this application
1913 if (parent->handle() && parent->handle()->isForeignWindow())
1914 break;
1915
1916 wnd = wnd->parent();
1917 }
1918 if (wnd) {
1919 const auto tlws = QApplication::topLevelWidgets();
1920 for (QWidget *tlw : tlws) {
1921 if (tlw->windowHandle() == wnd)
1922 return tlw;
1923 }
1924 }
1925 return nullptr;
1926}
1927
1929{
1930#ifndef Q_OS_MACOS
1931 // Some delayed focus event to ignore, unless we are on cocoa where
1932 // popups can be opened via right-click on inactive applications
1933 if (inPopupMode())
1934 return;
1935#endif
1937 QWidget *focusWidget = qt_tlw_for_window(focusWindow);
1939 // QTBUG-37126, Active X controls may set the focus on native child widgets.
1940 if (focusWindow && focusWidget && focusWindow != focusWidget->windowHandle()) {
1941 if (QWidgetWindow *widgetWindow = qobject_cast<QWidgetWindow *>(focusWindow))
1942 if (QWidget *widget = widgetWindow->widget())
1943 if (widget->inherits("QAxHostWidget"))
1945 }
1946
1947 // QApplication::setActiveWindow() will deliver window activation events for
1948 // QWidgetWindows. But for other subclasses of QWindow (like QQuickWindow), we
1949 // need to send them explicitly, like we do from the base class implementation.
1950 if (previous && !qobject_cast<QWidgetWindow *>(previous)) {
1952 QCoreApplication::sendEvent(previous, &de);
1953 }
1954
1955 if (focusWindow && !qobject_cast<QWidgetWindow *>(focusWindow)) {
1957 QCoreApplication::sendEvent(focusWindow, &ae);
1958 }
1959
1960 // don't call base class to avoid double delivery of WindowActivate/Deactivate events
1961}
1962
1969 bool *wrappingOccurred)
1970{
1972
1973 QWidget *f = toplevel->focusWidget();
1974 if (!f)
1975 f = toplevel;
1976
1977 QWidget *w = f;
1978 QWidget *test = f->nextInFocusChain();
1979 bool seenWindow = false;
1980 bool focusWidgetAfterWindow = false;
1981 while (test && test != f) {
1982 if (test->isWindow())
1983 seenWindow = true;
1984
1985 // If the next focus widget has a focus proxy, we need to check to ensure
1986 // that the proxy is in the correct parent-child direction (according to
1987 // \a next). This is to ensure that we can tab in and out of compound widgets
1988 // without getting stuck in a tab-loop between parent and child.
1989 QWidget *focusProxy = test->d_func()->deepestFocusProxy();
1990 auto effectiveFocusPolicy = [](QWidget *widget) {
1992 };
1993 const bool canTakeFocus = (effectiveFocusPolicy(focusProxy ? focusProxy : test)
1994 & focus_flag) == focus_flag;
1995 const bool composites = focusProxy ? (next ? focusProxy->isAncestorOf(test)
1996 : test->isAncestorOf(focusProxy))
1997 : false;
1998 if (canTakeFocus && !composites
1999 && test->isVisibleTo(toplevel) && test->isEnabled()
2000 && !(w->windowType() == Qt::SubWindow && !w->isAncestorOf(test))
2001 && (toplevel->windowType() != Qt::SubWindow || toplevel->isAncestorOf(test))
2002 && f != focusProxy) {
2003 w = test;
2004 if (seenWindow)
2005 focusWidgetAfterWindow = true;
2006 if (next)
2007 break;
2008 }
2009 test = test->nextInFocusChain();
2010 }
2011
2012 if (wrappingOccurred != nullptr)
2013 *wrappingOccurred = next ? focusWidgetAfterWindow : !focusWidgetAfterWindow;
2014
2015 if (w == f) {
2016 if (qt_in_tab_key_event) {
2017 w->window()->setAttribute(Qt::WA_KeyboardFocusChange);
2018 w->update();
2019 }
2020 return nullptr;
2021 }
2022 return w;
2023}
2024
2033{
2034 if ((!enter && !leave) || (enter == leave))
2035 return;
2036
2037 QWidgetList leaveList;
2038 QWidgetList enterList;
2039
2040 bool sameWindow = leave && enter && leave->window() == enter->window();
2041 if (leave && !sameWindow) {
2042 auto *w = leave;
2043 do {
2044 leaveList.append(w);
2045 } while (!w->isWindow() && (w = w->parentWidget()));
2046 }
2047 if (enter && !sameWindow) {
2048 auto *w = enter;
2049 do {
2050 enterList.append(w);
2051 } while (!w->isWindow() && (w = w->parentWidget()));
2052 }
2053 if (sameWindow) {
2054 int enterDepth = 0;
2055 int leaveDepth = 0;
2056 auto *e = enter;
2057 while (!e->isWindow() && (e = e->parentWidget()))
2058 enterDepth++;
2059 auto *l = leave;
2060 while (!l->isWindow() && (l = l->parentWidget()))
2061 leaveDepth++;
2062 QWidget* wenter = enter;
2063 QWidget* wleave = leave;
2064 while (enterDepth > leaveDepth) {
2065 wenter = wenter->parentWidget();
2066 enterDepth--;
2067 }
2068 while (leaveDepth > enterDepth) {
2069 wleave = wleave->parentWidget();
2070 leaveDepth--;
2071 }
2072 while (!wenter->isWindow() && wenter != wleave) {
2073 wenter = wenter->parentWidget();
2074 wleave = wleave->parentWidget();
2075 }
2076
2077 for (auto *w = leave; w != wleave; w = w->parentWidget())
2078 leaveList.append(w);
2079
2080 for (auto *w = enter; w != wenter; w = w->parentWidget())
2081 enterList.append(w);
2082 }
2083
2084 QEvent leaveEvent(QEvent::Leave);
2085 for (int i = 0; i < leaveList.size(); ++i) {
2086 auto *w = leaveList.at(i);
2088 QCoreApplication::sendEvent(w, &leaveEvent);
2089 if (w->testAttribute(Qt::WA_Hover) &&
2091 Q_ASSERT(instance());
2092 QHoverEvent he(QEvent::HoverLeave, QPointF(-1, -1), globalPosF, w->mapFromGlobal(globalPosF),
2094 qApp->d_func()->notify_helper(w, &he);
2095 }
2096 }
2097 }
2098 if (!enterList.isEmpty()) {
2099 // Guard against QGuiApplicationPrivate::lastCursorPosition initialized to qInf(), qInf().
2100 const QPointF globalPos = qIsInf(globalPosF.x())
2102 : globalPosF;
2103 const QPointF windowPos = std::as_const(enterList).back()->window()->mapFromGlobal(globalPos);
2104 for (auto it = enterList.crbegin(), end = enterList.crend(); it != end; ++it) {
2105 auto *w = *it;
2107 const QPointF localPos = w->mapFromGlobal(globalPos);
2108 QEnterEvent enterEvent(localPos, windowPos, globalPos);
2109 QCoreApplication::sendEvent(w, &enterEvent);
2110 if (w->testAttribute(Qt::WA_Hover) &&
2112 QHoverEvent he(QEvent::HoverEnter, windowPos, QPointF(-1, -1), globalPos,
2114 QMutableEventPoint::setPosition(he.point(0), localPos);
2115 qApp->d_func()->notify_helper(w, &he);
2116 }
2117 }
2118 }
2119 }
2120
2121#ifndef QT_NO_CURSOR
2122 // Update cursor for alien/graphics widgets.
2123
2124 const bool enterOnAlien = (enter && (isAlien(enter) || enter->testAttribute(Qt::WA_DontShowOnScreen)));
2125 // Whenever we leave an alien widget on X11/QPA, we need to reset its nativeParentWidget()'s cursor.
2126 // This is not required on Windows as the cursor is reset on every single mouse move.
2127 QWidget *parentOfLeavingCursor = nullptr;
2128 for (int i = 0; i < leaveList.size(); ++i) {
2129 auto *w = leaveList.at(i);
2130 if (!isAlien(w))
2131 break;
2132 if (w->testAttribute(Qt::WA_SetCursor)) {
2133 QWidget *parent = w->parentWidget();
2134 while (parent && parent->d_func()->data.in_destructor)
2135 parent = parent->parentWidget();
2136 parentOfLeavingCursor = parent;
2137 //continue looping, we need to find the downest alien widget with a cursor.
2138 // (downest on the screen)
2139 }
2140 }
2141 //check that we will not call qt_x11_enforce_cursor twice with the same native widget
2142 if (parentOfLeavingCursor && (!enterOnAlien
2143 || parentOfLeavingCursor->effectiveWinId() != enter->effectiveWinId())) {
2144#if QT_CONFIG(graphicsview)
2145 if (!parentOfLeavingCursor->window()->graphicsProxyWidget())
2146#endif
2147 {
2148 if (enter == QApplicationPrivate::desktop()) {
2149 qt_qpa_set_cursor(enter, true);
2150 } else {
2151 qt_qpa_set_cursor(parentOfLeavingCursor, true);
2152 }
2153 }
2154 }
2155 if (enterOnAlien) {
2156 QWidget *cursorWidget = enter;
2157 while (!cursorWidget->isWindow() && !cursorWidget->isEnabled())
2158 cursorWidget = cursorWidget->parentWidget();
2159
2160 if (!cursorWidget)
2161 return;
2162
2163#if QT_CONFIG(graphicsview)
2164 if (cursorWidget->window()->graphicsProxyWidget()) {
2165 QWidgetPrivate::nearestGraphicsProxyWidget(cursorWidget)->setCursor(cursorWidget->cursor());
2166 } else
2167#endif
2168 {
2169 qt_qpa_set_cursor(cursorWidget, true);
2170 }
2171 }
2172#endif
2173}
2174
2175/* exported for the benefit of testing tools */
2176Q_WIDGETS_EXPORT bool qt_tryModalHelper(QWidget *widget, QWidget **rettop)
2177{
2179}
2180
2185{
2186 widget = widget->window();
2188 return window && self->isWindowBlocked(window);
2189}
2190
2195
2197{
2199 QWindow *popupWindow = popupWidget ? popupWidget->windowHandle() : nullptr;
2200 return popupWindow == window || (!popupWindow && QWindowPrivate::get(window)->isPopup());
2201}
2202
2209{
2211 if (rettop)
2212 *rettop = top;
2213
2214 // the active popup widget always gets the input event
2216 return true;
2217
2218 return !isBlockedByModal(widget->window());
2219}
2220
2222{
2223 QWidget * top = nullptr;
2224
2226 return true;
2227
2228 bool block_event = false;
2229
2230 switch (type) {
2231 case QEvent::MouseButtonPress: // disallow mouse/key events
2233 case QEvent::MouseMove:
2234 case QEvent::KeyPress:
2235 case QEvent::KeyRelease:
2236 block_event = true;
2237 break;
2238 default:
2239 break;
2240 }
2241
2242 if (block_event && top && top->parentWidget() == nullptr)
2243 top->raise();
2244
2245 return !block_event;
2246}
2247
2249{
2250 return !self->modalWindowList.isEmpty();
2251}
2252
2253/*
2254 \internal
2255*/
2258 Qt::MouseButtons buttons, QWidget *buttonDown,
2259 QWidget *alienWidget)
2260{
2261 Q_ASSERT(candidate);
2262
2263 QWidget *mouseGrabber = QWidget::mouseGrabber();
2264 if (((type == QEvent::MouseMove && buttons) || (type == QEvent::MouseButtonRelease))
2265 && !buttonDown && !mouseGrabber) {
2266 return nullptr;
2267 }
2268
2269 if (alienWidget && alienWidget->internalWinId())
2270 alienWidget = nullptr;
2271
2272 QWidget *receiver = candidate;
2273
2274 if (!mouseGrabber)
2275 mouseGrabber = (buttonDown && !isBlockedByModal(buttonDown)) ? buttonDown : alienWidget;
2276
2277 if (mouseGrabber && mouseGrabber != candidate) {
2278 receiver = mouseGrabber;
2279 *pos = receiver->mapFromGlobal(candidate->mapToGlobal(windowPos));
2280 }
2281
2282 return receiver;
2283
2284}
2285
2286/*
2287 \internal
2288*/
2290 QWidget *alienWidget, QWidget *nativeWidget,
2291 QWidget **buttonDown, QPointer<QWidget> &lastMouseReceiver,
2292 bool spontaneous, bool onlyDispatchEnterLeave)
2293{
2294 Q_ASSERT(receiver);
2295 Q_ASSERT(event);
2296 Q_ASSERT(nativeWidget);
2297 Q_ASSERT(buttonDown);
2298
2299 if (alienWidget && !isAlien(alienWidget))
2300 alienWidget = nullptr;
2301
2302 QPointer<QWidget> receiverGuard = receiver;
2303 QPointer<QWidget> nativeGuard = nativeWidget;
2304 QPointer<QWidget> alienGuard = alienWidget;
2305 QPointer<QWidget> activePopupWidget = QApplication::activePopupWidget();
2306
2307 const bool graphicsWidget = nativeWidget->testAttribute(Qt::WA_DontShowOnScreen);
2308
2309 bool widgetUnderMouse = QRectF(receiver->rect()).contains(event->position());
2310
2311 // Clear the obsolete leaveAfterRelease value, if mouse button has been released but
2312 // leaveAfterRelease has not been updated.
2313 // This happens e.g. when modal dialog or popup is shown as a response to button click.
2314 if (leaveAfterRelease && !*buttonDown && !event->buttons())
2315 leaveAfterRelease = nullptr;
2316
2317 if (*buttonDown) {
2318 if (!graphicsWidget) {
2319 // Register the widget that shall receive a leave event
2320 // after the last button is released.
2321 if ((alienWidget || !receiver->internalWinId()) && !leaveAfterRelease && !QWidget::mouseGrabber())
2322 leaveAfterRelease = *buttonDown;
2323 if (event->type() == QEvent::MouseButtonRelease && !event->buttons())
2324 *buttonDown = nullptr;
2325 }
2326 } else if (lastMouseReceiver && widgetUnderMouse) {
2327 // Dispatch enter/leave if we move:
2328 // 1) from an alien widget to another alien widget or
2329 // from a native widget to an alien widget (first OR case)
2330 // 2) from an alien widget to a native widget (second OR case)
2331 if ((alienWidget && alienWidget != lastMouseReceiver)
2332 || (isAlien(lastMouseReceiver) && !alienWidget)) {
2333 if (activePopupWidget) {
2334 if (!QWidget::mouseGrabber())
2335 dispatchEnterLeave(alienWidget ? alienWidget : nativeWidget, lastMouseReceiver, event->globalPosition());
2336 } else {
2337 dispatchEnterLeave(receiver, lastMouseReceiver, event->globalPosition());
2338 }
2339
2340 }
2341 }
2342
2343 // We need this quard in case someone opens a modal dialog / popup. If that's the case
2344 // leaveAfterRelease is set to null, but we shall not update lastMouseReceiver.
2345 const bool wasLeaveAfterRelease = leaveAfterRelease != nullptr;
2346 bool result = true;
2347 // This code is used for sending the synthetic enter/leave events for cases where it is needed
2348 // due to other events causing the widget under the mouse to change. However in those cases
2349 // we do not want to send the mouse event associated with this call, so this enables us to
2350 // not send the unneeded mouse event
2351 if (!onlyDispatchEnterLeave) {
2352 if (spontaneous)
2353 result = QApplication::sendSpontaneousEvent(receiver, event);
2354 else
2356 }
2357
2358 if (!graphicsWidget && leaveAfterRelease && event->type() == QEvent::MouseButtonRelease
2359 && !event->buttons() && QWidget::mouseGrabber() != leaveAfterRelease) {
2360 // Dispatch enter/leave if:
2361 // 1) the mouse grabber is an alien widget
2362 // 2) the button is released on an alien widget
2363 QWidget *enter = nullptr;
2364 if (nativeGuard)
2365 enter = alienGuard ? alienWidget : nativeWidget;
2366 else // The receiver is typically deleted on mouse release with drag'n'drop.
2367 enter = QApplication::widgetAt(event->globalPosition().toPoint());
2368 dispatchEnterLeave(enter, leaveAfterRelease, event->globalPosition());
2369 leaveAfterRelease = nullptr;
2370 lastMouseReceiver = enter;
2371 } else if (!wasLeaveAfterRelease) {
2372 if (activePopupWidget) {
2373 if (!QWidget::mouseGrabber())
2374 lastMouseReceiver = alienGuard ? alienWidget : (nativeGuard ? nativeWidget : nullptr);
2375 } else {
2376 lastMouseReceiver = receiverGuard ? receiver : QApplication::widgetAt(event->globalPosition().toPoint());
2377 }
2378 }
2379
2380 return result;
2381}
2382
2383/*
2384 This function should only be called when the widget changes visibility, i.e.
2385 when the \a widget is shown, hidden or deleted. This function does nothing
2386 if the widget is a top-level or native, i.e. not an alien widget. In that
2387 case enter/leave events are generated by the underlying windowing system.
2388*/
2389extern QPointer<QWidget> qt_last_mouse_receiver;
2390extern Q_WIDGETS_EXPORT QWidget *qt_button_down;
2392{
2393#ifndef QT_NO_CURSOR
2394 if (!widget || widget->isWindow())
2395 return;
2396 const bool widgetInShow = widget->isVisible() && !widget->data->in_destructor;
2397 if (!widgetInShow && widget != qt_last_mouse_receiver)
2398 return; // Widget was not under the cursor when it was hidden/deleted.
2399
2400 if (widgetInShow && widget->parentWidget()->data->in_show)
2401 return; // Ignore recursive show.
2402
2403 QWidget *mouseGrabber = QWidget::mouseGrabber();
2404 if (mouseGrabber && mouseGrabber != widget)
2405 return; // Someone else has the grab; enter/leave should not occur.
2406
2407 QWidget *tlw = widget->window();
2408 if (tlw->data->in_destructor || tlw->data->is_closing)
2409 return; // Closing down the business.
2410
2411 if (widgetInShow && (!qt_last_mouse_receiver || qt_last_mouse_receiver->window() != tlw))
2412 return; // Mouse cursor not inside the widget's top-level.
2413
2414 const QPoint globalPos(QCursor::pos());
2415 QPoint windowPos = tlw->mapFromGlobal(globalPos);
2416
2417 // Find the current widget under the mouse. If this function was called from
2418 // the widget's destructor, we have to make sure childAt() doesn't take into
2419 // account widgets that are about to be destructed.
2420 QWidget *widgetUnderCursor = tlw->d_func()->childAt_helper(windowPos, widget->data->in_destructor);
2421 if (!widgetUnderCursor)
2422 widgetUnderCursor = tlw;
2423 QPoint pos = widgetUnderCursor->mapFrom(tlw, windowPos);
2424
2425 if (widgetInShow && widgetUnderCursor != widget && !widget->isAncestorOf(widgetUnderCursor))
2426 return; // Mouse cursor not inside the widget or any of its children.
2427
2428 if (widget->data->in_destructor && qt_button_down == widget)
2429 qt_button_down = nullptr;
2430
2431 // A mouse move is not actually sent, but we utilize the sendMouseEvent() call to send the
2432 // enter/leave events as appropriate
2434 sendMouseEvent(widgetUnderCursor, &e, widgetUnderCursor, tlw, &qt_button_down, qt_last_mouse_receiver, true, true);
2435#else // !QT_NO_CURSOR
2437#endif // QT_NO_CURSOR
2438}
2439
2449{
2450 CHECK_QAPP_INSTANCE(nullptr)
2451 if (!qt_desktopWidget || // not created yet
2452 !(qt_desktopWidget->windowType() == Qt::Desktop)) { // reparented away
2453 qt_desktopWidget = new QWidget(nullptr, Qt::Desktop);
2454 }
2455 return qt_desktopWidget;
2456}
2457
2458/*
2459 Sets the time after which a drag should start to \a ms ms.
2460
2461 \sa startDragTime()
2462*/
2463
2465{
2466 QGuiApplication::styleHints()->setStartDragTime(ms);
2467}
2468
2487{
2488 return QGuiApplication::styleHints()->startDragTime();
2489}
2490
2491/*
2492 Sets the distance after which a drag should start to \a l pixels.
2493
2494 \sa startDragDistance()
2495*/
2496
2498{
2499 QGuiApplication::styleHints()->setStartDragDistance(l);
2500}
2501
2526{
2527 return QGuiApplication::styleHints()->startDragDistance();
2528}
2529
2561{
2562 return QGuiApplication::exec();
2563}
2564
2568{
2569 Q_D(QApplication);
2570 // no events are delivered after ~QCoreApplication() has started
2572 return true;
2573
2574 if (Q_UNLIKELY(!receiver)) { // serious error
2575 qWarning("QApplication::notify: Unexpected null receiver");
2576 return true;
2577 }
2578
2579#ifndef QT_NO_DEBUG
2581#endif
2582
2583 const bool isWindowType = receiver->isWindowType();
2584 const bool isWidgetType = receiver->isWidgetType();
2585 if (isWindowType
2587 return true; // Platform plugin ate the event
2588 }
2589
2591
2592#ifndef QT_NO_GESTURES
2593 // walk through parents and check for gestures
2594 if (d->gestureManager) {
2595 switch (e->type()) {
2596 case QEvent::Paint:
2597 case QEvent::MetaCall:
2606 case QEvent::Style:
2607 case QEvent::IconDrag:
2615 break;
2616 default:
2617 if (d->gestureManager->thread() == QThread::currentThread()) {
2618 if (isWidgetType) {
2619 if (d->gestureManager->filterEvent(static_cast<QWidget *>(receiver), e))
2620 return true;
2621 } else {
2622 // a special case for events that go to QGesture objects.
2623 // We pass the object to the gesture manager and it'll figure
2624 // out if it's QGesture or not.
2625 if (d->gestureManager->filterEvent(receiver, e))
2626 return true;
2627 }
2628 }
2629 break;
2630 }
2631 }
2632#endif // QT_NO_GESTURES
2633
2634 switch (e->type()) {
2637 // Close all popups (triggers when switching applications
2638 // by pressing ALT-TAB on Windows, which is not receive as key event.
2639 // triggers when the screen rotates.)
2640 d->closeAllPopups();
2641 break;
2642 case QEvent::Wheel: // User input and window activation makes tooltips sleep
2644 case QEvent::KeyPress:
2645 case QEvent::KeyRelease:
2646 case QEvent::FocusOut:
2647 case QEvent::FocusIn:
2651 d->toolTipFallAsleep.stop();
2652 Q_FALLTHROUGH();
2653 case QEvent::Leave:
2654 d->toolTipWakeUp.stop();
2655 break;
2656 default:
2657 break;
2658 }
2659
2660 switch (e->type()) {
2661 case QEvent::KeyPress: {
2662 QKeyEvent* keyEvent = static_cast<QKeyEvent*>(e);
2663 const int key = keyEvent->key();
2664 // When a key press is received which is not spontaneous then it needs to
2665 // be manually sent as a shortcut override event to ensure that any
2666 // matching shortcut is triggered first. This enables emulation/playback
2667 // of recorded events to still have the same effect.
2668 if (!e->spontaneous() && isWidgetType
2669 && qt_sendShortcutOverrideEvent(static_cast<QWidget *>(receiver), keyEvent->timestamp(),
2670 key, keyEvent->modifiers(), keyEvent->text(),
2671 keyEvent->isAutoRepeat(), keyEvent->count())) {
2672 return true;
2673 }
2675 || key == Qt::Key_Tab
2676 || key == Qt::Key_Left
2677 || key == Qt::Key_Up
2678 || key == Qt::Key_Right
2679 || key == Qt::Key_Down);
2680 break;
2681 }
2682 default:
2683 break;
2684 }
2685
2686 bool res = false;
2687 if (isWidgetType) {
2688 QWidget * w = static_cast<QWidget *>(receiver);
2689 switch (e->type()) {
2691 case QEvent::KeyPress:
2692 case QEvent::KeyRelease: {
2693 QKeyEvent* key = static_cast<QKeyEvent*>(e);
2694 bool def = key->isAccepted();
2695 /*
2696 QLineEdit will emit a signal on Key_Return, but
2697 ignore the event, and sometimes the connected
2698 slot deletes the QLineEdit (common in itemview
2699 delegates), so we have to check if the widget
2700 was destroyed even if the event was ignored (to
2701 prevent a crash)
2702
2703 Note that we don't have to reset pr while
2704 propagating (because the original receiver will
2705 be destroyed if one of its ancestors is)
2706 */
2707 QPointer<QObject> pr = receiver;
2708 while (w) {
2709 if (def)
2710 key->accept();
2711 else
2712 key->ignore();
2713 res = d->notify_helper(w, e);
2714
2715 if (res && key->isAccepted())
2716 break;
2717 if (!pr || w->isWindow())
2718 break;
2719
2720 w = w->parentWidget();
2721 }
2722 qt_in_tab_key_event = false;
2723 break;
2724 }
2728 case QEvent::MouseMove: {
2729 QMouseEvent* mouse = static_cast<QMouseEvent*>(e);
2730 QPoint relpos = mouse->position().toPoint();
2731
2732 if (e->spontaneous()) {
2733 if (e->type() != QEvent::MouseMove)
2734 QApplicationPrivate::giveFocusAccordingToFocusPolicy(w, e, relpos);
2735
2736 // ### Qt 7 These dynamic tool tips should be an OPT-IN feature. Some platforms
2737 // like macOS (probably others too), can optimize their views by not
2738 // dispatching mouse move events. We have attributes to control hover,
2739 // and mouse tracking, but as long as we are deciding to implement this
2740 // feature without choice of opting-in or out, you ALWAYS have to have
2741 // tracking enabled. Therefore, the other properties give a false sense of
2742 // performance enhancement.
2743 if (e->type() == QEvent::MouseMove && mouse->buttons() == 0
2744 && w->rect().contains(relpos)) { // Outside due to mouse grab?
2745 d->toolTipWidget = w;
2746 d->toolTipPos = relpos;
2747 d->toolTipGlobalPos = mouse->globalPosition().toPoint();
2748 QStyle *s = d->toolTipWidget->style();
2749 int wakeDelay = s->styleHint(QStyle::SH_ToolTip_WakeUpDelay, nullptr, d->toolTipWidget, nullptr);
2750 d->toolTipWakeUp.start(d->toolTipFallAsleep.isActive() ? 20 : wakeDelay, this);
2751 }
2752 }
2753
2754 bool eventAccepted = mouse->isAccepted();
2755
2756 QPointer<QWidget> pw = w;
2757 while (w) {
2758 QMouseEvent me(mouse->type(), relpos, mouse->scenePosition(), mouse->globalPosition().toPoint(),
2759 mouse->button(), mouse->buttons(), mouse->modifiers(), mouse->source(),
2760 mouse->pointingDevice());
2761 me.m_spont = mouse->spontaneous();
2762 me.setTimestamp(mouse->timestamp());
2763 QMutableSinglePointEvent::from(me).setDoubleClick(QMutableSinglePointEvent::from(mouse)->isDoubleClick());
2764 // throw away any mouse-tracking-only mouse events
2765 if (!w->hasMouseTracking()
2766 && mouse->type() == QEvent::MouseMove && mouse->buttons() == 0) {
2767 // but still send them through all application event filters (normally done by notify_helper)
2768 d->sendThroughApplicationEventFilters(w, w == receiver ? mouse : &me);
2769 res = true;
2770 } else {
2771 w->setAttribute(Qt::WA_NoMouseReplay, false);
2772 res = d->notify_helper(w, w == receiver ? mouse : &me);
2773 e->m_spont = false;
2774 }
2775 eventAccepted = (w == receiver ? mouse : &me)->isAccepted();
2776 if (res && eventAccepted)
2777 break;
2778 if (w->isWindow() || w->testAttribute(Qt::WA_NoMousePropagation))
2779 break;
2780 relpos += w->pos();
2781 w = w->parentWidget();
2782 }
2783
2784 mouse->setAccepted(eventAccepted);
2785
2786 if (e->type() == QEvent::MouseMove) {
2787 if (!pw)
2788 break;
2789
2790 w = static_cast<QWidget *>(receiver);
2791 relpos = mouse->position().toPoint();
2792 QPoint diff = relpos - w->mapFromGlobal(mouse->globalPosition().toPoint());
2793 while (w) {
2794 if (w->testAttribute(Qt::WA_Hover) &&
2796 QHoverEvent he(QEvent::HoverMove, mouse->scenePosition(), mouse->globalPosition(), relpos - diff, mouse->modifiers());
2797 QMutableEventPoint::setPosition(he.point(0), relpos);
2798 d->notify_helper(w, &he);
2799 }
2800 if (w->isWindow() || w->testAttribute(Qt::WA_NoMousePropagation))
2801 break;
2802 relpos += w->pos();
2803 w = w->parentWidget();
2804 }
2805 }
2806
2807 d->hoverGlobalPos = mouse->globalPosition().toPoint();
2808 break;
2809 }
2810#if QT_CONFIG(wheelevent)
2811 case QEvent::Wheel: {
2812 // QTBUG-40656, QTBUG-42731: ignore wheel events when a popup (QComboBox) is open.
2813 if (const QWidget *popup = QApplication::activePopupWidget()) {
2814 if (w->window() != popup)
2815 return true;
2816 }
2817
2818 QWheelEvent* wheel = static_cast<QWheelEvent*>(e);
2819 if (!wheel->spontaneous()) {
2820 /*
2821 Synthesized events shouldn't propagate, e.g. QScrollArea passes events from the
2822 viewport on to the scrollbars, which might ignore the event if there is no more
2823 space to scroll. If we would propagate, the event would come back to the viewport.
2824 */
2825 res = d->notify_helper(w, wheel);
2826 break;
2827 }
2828
2829 const Qt::ScrollPhase phase = wheel->phase();
2830 QPoint relpos = wheel->position().toPoint();
2831
2832 // Ideally, we should lock on a widget when it starts receiving wheel
2833 // events. This avoids other widgets to start receiving those events
2834 // as the mouse cursor hovers them. However, given the way common
2835 // wheeled mice work, there's no certain way of connecting different
2836 // wheel events as a stream. This results in the NoScrollPhase case,
2837 // where we just send the event from the original receiver and up its
2838 // hierarchy until the event gets accepted.
2839 //
2840 // In the case of more evolved input devices, like Apple's trackpad or
2841 // Magic Mouse, we receive the scroll phase information. This helps us
2842 // connect wheel events as a stream and therefore makes it easier to
2843 // lock on the widget onto which the scrolling was initiated.
2844 //
2845 // We assume that, when supported, the phase cycle follows the pattern:
2846 //
2847 // ScrollBegin (ScrollUpdate* ScrollMomentum* ScrollEnd)+
2848 //
2849 // This means that we can have scrolling sequences (starting with ScrollBegin)
2850 // or partial sequences (after a ScrollEnd and starting with ScrollUpdate).
2851
2852 // a widget has already grabbed the wheel for a sequence
2853 if (QApplicationPrivate::wheel_widget) {
2854 Q_ASSERT(phase != Qt::NoScrollPhase);
2855 w = QApplicationPrivate::wheel_widget;
2856 relpos = w->mapFromGlobal(wheel->globalPosition().toPoint());
2857 }
2858 /*
2859 Start or finish a scrolling sequence by grabbing/releasing the wheel via
2860 wheel_widget. The sequence might be partial (ie. not start with ScrollBegin),
2861 e.g. if the previous wheel_widget was destroyed mid-sequence.
2862 */
2863 switch (phase) {
2864 case Qt::ScrollEnd:
2865 QApplicationPrivate::wheel_widget = nullptr;
2866 break;
2867 case Qt::ScrollBegin:
2868 QApplicationPrivate::wheel_widget = w;
2869 Q_FALLTHROUGH();
2870 case Qt::ScrollUpdate:
2871 case Qt::ScrollMomentum:
2872 if (!QApplicationPrivate::wheel_widget)
2873 QApplicationPrivate::wheel_widget = w;
2874 Q_FALLTHROUGH();
2875 case Qt::NoScrollPhase:
2876 QApplicationPrivate::giveFocusAccordingToFocusPolicy(w, e, relpos);
2877 break;
2878 // no default: - we want warnings if we don't handle all phases explicitly
2879 }
2880
2881 QWheelEvent we(relpos, wheel->globalPosition(), wheel->pixelDelta(), wheel->angleDelta(), wheel->buttons(),
2882 wheel->modifiers(), phase, wheel->inverted(), wheel->source(), wheel->pointingDevice());
2883
2884 we.setTimestamp(wheel->timestamp());
2885 bool eventAccepted;
2886 do {
2887 // events are delivered as accepted and ignored by the default event handler
2888 // since we always send the same QWheelEvent object, we need to reset the accepted state
2889 we.setAccepted(true);
2890 we.m_spont = wheel->spontaneous() && w == receiver;
2891 res = d->notify_helper(w, &we);
2892 eventAccepted = we.isAccepted();
2893 if (res && eventAccepted)
2894 break;
2895 if (w->isWindow() || w->testAttribute(Qt::WA_NoMousePropagation))
2896 break;
2897
2898 QMutableEventPoint::setPosition(we.point(0), we.position() + w->pos());
2899 w = w->parentWidget();
2900 } while (w);
2901 wheel->setAccepted(eventAccepted);
2902 break;
2903 }
2904#endif
2905#ifndef QT_NO_CONTEXTMENU
2906 case QEvent::ContextMenu: {
2907 QContextMenuEvent *context = static_cast<QContextMenuEvent*>(e);
2908 QPoint relpos = context->pos();
2909 bool eventAccepted = context->isAccepted();
2910 while (w) {
2911 QContextMenuEvent ce(context->reason(), relpos, context->globalPos(), context->modifiers());
2912 ce.m_spont = e->spontaneous();
2913 res = d->notify_helper(w, w == receiver ? context : &ce);
2914 eventAccepted = ((w == receiver) ? context : &ce)->isAccepted();
2915 e->m_spont = false;
2916
2917 if (res && eventAccepted)
2918 break;
2919 if (w->isWindow() || w->testAttribute(Qt::WA_NoMousePropagation))
2920 break;
2921
2922 relpos += w->pos();
2923 w = w->parentWidget();
2924 }
2925 context->setAccepted(eventAccepted);
2926 break;
2927 }
2928#endif // QT_NO_CONTEXTMENU
2929#if QT_CONFIG(tabletevent)
2930 case QEvent::TabletMove:
2932 case QEvent::TabletRelease: {
2933 QTabletEvent *tablet = static_cast<QTabletEvent*>(e);
2934 QPointF relpos = tablet->position();
2935 bool eventAccepted = tablet->isAccepted();
2936 while (w) {
2937 QTabletEvent te(tablet->type(), tablet->pointingDevice(), relpos, tablet->globalPosition(),
2938 tablet->pressure(), tablet->xTilt(), tablet->yTilt(),
2939 tablet->tangentialPressure(), tablet->rotation(), tablet->z(),
2940 tablet->modifiers(), tablet->button(), tablet->buttons());
2941 te.m_spont = e->spontaneous();
2942 te.setTimestamp(tablet->timestamp());
2943 te.setAccepted(false);
2944 res = d->notify_helper(w, w == receiver ? tablet : &te);
2945 eventAccepted = ((w == receiver) ? tablet : &te)->isAccepted();
2946 e->m_spont = false;
2947 if (res && eventAccepted)
2948 break;
2949 if (w->isWindow() || w->testAttribute(Qt::WA_NoMousePropagation))
2950 break;
2951
2952 relpos += w->pos();
2953 w = w->parentWidget();
2954 }
2955 tablet->setAccepted(eventAccepted);
2956 break;
2957 }
2958#endif // QT_CONFIG(tabletevent)
2959
2960#if QT_CONFIG(tooltip) || QT_CONFIG(whatsthis)
2961 case QEvent::ToolTip:
2962 case QEvent::WhatsThis:
2964 QHelpEvent *help = static_cast<QHelpEvent*>(e);
2965 QPoint relpos = help->pos();
2966 bool eventAccepted = help->isAccepted();
2967 while (w) {
2968 QHelpEvent he(help->type(), relpos, help->globalPos());
2969 he.m_spont = e->spontaneous();
2970 res = d->notify_helper(w, w == receiver ? help : &he);
2971 e->m_spont = false;
2972 eventAccepted = (w == receiver ? help : &he)->isAccepted();
2973 if (res && eventAccepted)
2974 break;
2975 if (w->isWindow())
2976 break;
2977
2978 relpos += w->pos();
2979 w = w->parentWidget();
2980 }
2981 help->setAccepted(eventAccepted);
2982 break;
2983 }
2984#endif
2985#if QT_CONFIG(statustip) || QT_CONFIG(whatsthis)
2986 case QEvent::StatusTip:
2988 while (w) {
2989 res = d->notify_helper(w, e);
2990 if (res && e->isAccepted())
2991 break;
2992 if (w->isWindow())
2993 break;
2994 w = w->parentWidget();
2995 }
2996 break;
2997#endif
2998
2999#if QT_CONFIG(draganddrop)
3000 case QEvent::DragEnter: {
3001 QDragEnterEvent *dragEvent = static_cast<QDragEnterEvent *>(e);
3002#if QT_CONFIG(graphicsview)
3003 // QGraphicsProxyWidget handles its own propagation,
3004 // and we must not change QDragManagers currentTarget.
3005 const auto &extra = w->window()->d_func()->extra;
3006 if (extra && extra->proxyWidget) {
3007 res = d->notify_helper(w, dragEvent);
3008 break;
3009 }
3010#endif
3011 while (w) {
3012 if (w->isEnabled() && w->acceptDrops()) {
3013 res = d->notify_helper(w, dragEvent);
3014 if (res && dragEvent->isAccepted()) {
3015 QDragManager::self()->setCurrentTarget(w);
3016 break;
3017 }
3018 }
3019 if (w->isWindow())
3020 break;
3021 dragEvent->m_pos = w->mapToParent(dragEvent->m_pos);
3022 w = w->parentWidget();
3023 }
3024 break;
3025 }
3026 case QEvent::DragMove:
3027 case QEvent::Drop:
3028 case QEvent::DragLeave: {
3029#if QT_CONFIG(graphicsview)
3030 // QGraphicsProxyWidget handles its own propagation,
3031 // and we must not change QDragManagers currentTarget.
3032 const auto &extra = w->window()->d_func()->extra;
3033 bool isProxyWidget = extra && extra->proxyWidget;
3034 if (!isProxyWidget)
3035#endif
3036 w = qobject_cast<QWidget *>(QDragManager::self()->currentTarget());
3037
3038 if (!w) {
3039 // The widget that received DragEnter didn't accept the event, so we have no
3040 // current drag target in the QDragManager. But DragLeave still needs to be
3041 // dispatched so that enter/leave events are in balance (and so that UnderMouse
3042 // gets cleared).
3043 if (e->type() == QEvent::DragLeave)
3044 w = static_cast<QWidget *>(receiver);
3045 else
3046 break;
3047 }
3048 if (e->type() == QEvent::DragMove || e->type() == QEvent::Drop) {
3049 QDropEvent *dragEvent = static_cast<QDropEvent *>(e);
3050 QWidget *origReceiver = static_cast<QWidget *>(receiver);
3051 while (origReceiver && w != origReceiver) {
3052 dragEvent->m_pos = origReceiver->mapToParent(dragEvent->m_pos);
3053 origReceiver = origReceiver->parentWidget();
3054 }
3055 }
3056 res = d->notify_helper(w, e);
3057 if (e->type() != QEvent::DragMove
3058#if QT_CONFIG(graphicsview)
3059 && !isProxyWidget
3060#endif
3061 )
3062 QDragManager::self()->setCurrentTarget(nullptr, e->type() == QEvent::Drop);
3063 break;
3064 }
3065#endif // QT_CONFIG(draganddrop)
3066 case QEvent::TouchBegin: {
3067 // Note: TouchUpdate and TouchEnd events are never propagated
3068 QMutableTouchEvent *touchEvent = QMutableTouchEvent::from(static_cast<QTouchEvent *>(e));
3069 bool eventAccepted = touchEvent->isAccepted();
3070 bool acceptTouchEvents = w->testAttribute(Qt::WA_AcceptTouchEvents);
3071
3072 if (acceptTouchEvents && e->spontaneous()
3073 && touchEvent->device()->type() != QInputDevice::DeviceType::TouchPad) {
3074 const QPoint localPos = touchEvent->points()[0].position().toPoint();
3075 QApplicationPrivate::giveFocusAccordingToFocusPolicy(w, e, localPos);
3076 }
3077
3078#ifndef QT_NO_GESTURES
3079 QPointer<QWidget> gesturePendingWidget;
3080#endif
3081
3082 while (w) {
3083 // first, try to deliver the touch event
3084 acceptTouchEvents = w->testAttribute(Qt::WA_AcceptTouchEvents);
3085 touchEvent->setTarget(w);
3086 touchEvent->setAccepted(acceptTouchEvents);
3087 QPointer<QWidget> p = w;
3088 res = acceptTouchEvents && d->notify_helper(w, touchEvent);
3089 eventAccepted = touchEvent->isAccepted();
3090 if (p.isNull()) {
3091 // widget was deleted
3092 w = nullptr;
3093 } else {
3094 w->setAttribute(Qt::WA_WState_AcceptedTouchBeginEvent, res && eventAccepted);
3095 }
3096 touchEvent->m_spont = false;
3097 if (res && eventAccepted) {
3098 // the first widget to accept the TouchBegin gets an implicit grab.
3099 d->activateImplicitTouchGrab(w, touchEvent);
3100 break;
3101 }
3102#ifndef QT_NO_GESTURES
3103 if (gesturePendingWidget.isNull() && w && QGestureManager::gesturePending(w))
3104 gesturePendingWidget = w;
3105#endif
3106 if (!w || w->isWindow() || w->testAttribute(Qt::WA_NoMousePropagation))
3107 break;
3108
3109 const QPoint offset = w->pos();
3110 w = w->parentWidget();
3111 touchEvent->setTarget(w);
3112 for (int i = 0; i < touchEvent->pointCount(); ++i) {
3113 auto &pt = touchEvent->point(i);
3114 QMutableEventPoint::setPosition(pt, pt.position() + offset);
3115 }
3116 }
3117
3118#ifndef QT_NO_GESTURES
3119 if (!eventAccepted && !gesturePendingWidget.isNull()) {
3120 // the first widget subscribed to a gesture gets an implicit grab for all
3121 // points, also for events and event points that have not been accepted.
3122 d->activateImplicitTouchGrab(gesturePendingWidget, touchEvent, QApplicationPrivate::GrabAllPoints);
3123 }
3124#endif
3125
3126 touchEvent->setAccepted(eventAccepted);
3127 break;
3128 }
3130 case QEvent::TouchEnd:
3131 // We may get here if the widget is subscribed to a gesture,
3132 // but has not accepted TouchBegin. Propagate touch events
3133 // only if TouchBegin has been accepted.
3134 if (w->testAttribute(Qt::WA_WState_AcceptedTouchBeginEvent))
3135 res = d->notify_helper(w, e);
3136 break;
3138 inputMethod()->show();
3139 break;
3141 inputMethod()->hide();
3142 break;
3143
3144#ifndef QT_NO_GESTURES
3146 while (w) {
3147 e->ignore();
3148 res = d->notify_helper(w, e);
3149 if (res && e->isAccepted())
3150 break;
3151 if (w->isWindow())
3152 break;
3153 w = w->parentWidget();
3154 }
3155 break;
3156 case QEvent::Gesture:
3158 QGestureEvent *gestureEvent = static_cast<QGestureEvent *>(e);
3159 QList<QGesture *> allGestures = gestureEvent->gestures();
3160
3161 bool eventAccepted = gestureEvent->isAccepted();
3162 bool wasAccepted = eventAccepted;
3163 while (w) {
3164 // send only gestures the widget expects
3165 QList<QGesture *> gestures;
3166 QWidgetPrivate *wd = w->d_func();
3167 for (int i = 0; i < allGestures.size();) {
3168 QGesture *g = allGestures.at(i);
3172 bool deliver = contextit != wd->gestureContext.end() &&
3173 (g->state() == Qt::GestureStarted || w == receiver ||
3174 (contextit.value() & Qt::ReceivePartialGestures));
3175 if (deliver) {
3176 allGestures.removeAt(i);
3177 gestures.append(g);
3178 } else {
3179 ++i;
3180 }
3181 }
3182 if (!gestures.isEmpty()) { // we have gestures for this w
3183 QGestureEvent ge(gestures);
3184 ge.t = gestureEvent->t;
3185 ge.m_spont = gestureEvent->spontaneous();
3186 ge.m_accept = wasAccepted;
3187 ge.m_accepted = gestureEvent->m_accepted;
3188 res = d->notify_helper(w, &ge);
3189 gestureEvent->m_spont = false;
3190 eventAccepted = ge.isAccepted();
3191 for (int i = 0; i < gestures.size(); ++i) {
3192 QGesture *g = gestures.at(i);
3193 // Ignore res [event return value] because handling of multiple gestures
3194 // packed into a single QEvent depends on not consuming the event
3195 if (eventAccepted || ge.isAccepted(g)) {
3196 // if the gesture was accepted, mark the target widget for it
3197 gestureEvent->m_targetWidgets[g->gestureType()] = w;
3198 gestureEvent->setAccepted(g, true);
3199 } else {
3200 // if the gesture was explicitly ignored by the application,
3201 // put it back so a parent can get it
3202 allGestures.append(g);
3203 }
3204 }
3205 }
3206 if (allGestures.isEmpty()) // everything delivered
3207 break;
3208 if (w->isWindow())
3209 break;
3210 w = w->parentWidget();
3211 }
3212 for (QGesture *g : std::as_const(allGestures))
3213 gestureEvent->setAccepted(g, false);
3214 gestureEvent->m_accept = false; // to make sure we check individual gestures
3215 break;
3216 }
3217#endif // QT_NO_GESTURES
3218#ifdef Q_OS_MAC
3219 // Enable touch events on enter, disable on leave.
3220 typedef void (*RegisterTouchWindowFn)(QWindow *, bool);
3221 case QEvent::Enter:
3222 if (w->testAttribute(Qt::WA_AcceptTouchEvents)) {
3223 RegisterTouchWindowFn registerTouchWindow = reinterpret_cast<RegisterTouchWindowFn>
3224 (platformNativeInterface()->nativeResourceFunctionForIntegration("registertouchwindow"));
3225 if (registerTouchWindow)
3226 registerTouchWindow(w->window()->windowHandle(), true);
3227 }
3228 res = d->notify_helper(receiver, e);
3229 break;
3230 case QEvent::Leave:
3231 if (w->testAttribute(Qt::WA_AcceptTouchEvents)) {
3232 RegisterTouchWindowFn registerTouchWindow = reinterpret_cast<RegisterTouchWindowFn>
3233 (platformNativeInterface()->nativeResourceFunctionForIntegration("registertouchwindow"));
3234 if (registerTouchWindow)
3235 registerTouchWindow(w->window()->windowHandle(), false);
3236 }
3237 res = d->notify_helper(receiver, e);
3238 break;
3239#endif
3240 default:
3241 res = d->notify_helper(receiver, e);
3242 break;
3243 }
3244 } else {
3245 res = d->notify_helper(receiver, e);
3246 }
3247
3248 return res;
3249}
3250
3252{
3253 // These tracepoints (and the whole function, actually) are very similar
3254 // to the ones in QCoreApplicationPrivate::notify_helper; the reason for their
3255 // duplication is because tracepoint symbols are not exported by QtCore.
3256 // If you adjust the tracepoints here, consider adjusting QCoreApplicationPrivate too.
3257 Q_TRACE(QApplication_notify_entry, receiver, e, e->type());
3258 bool consumed = false;
3259 bool filtered = false;
3260 Q_TRACE_EXIT(QApplication_notify_exit, consumed, filtered);
3261
3262 // send to all application event filters
3264 && receiver->d_func()->threadData.loadRelaxed()->thread.loadAcquire() == mainThread()
3265 && sendThroughApplicationEventFilters(receiver, e)) {
3266 filtered = true;
3267 return filtered;
3268 }
3269
3270 if (receiver->isWidgetType()) {
3271 QWidget *widget = static_cast<QWidget *>(receiver);
3272
3273#if !defined(QT_NO_CURSOR)
3274 // toggle HasMouse widget state on enter and leave
3275 if ((e->type() == QEvent::Enter || e->type() == QEvent::DragEnter) &&
3278 else if (e->type() == QEvent::Leave || e->type() == QEvent::DragLeave)
3280#endif
3281
3282 if (QLayout *layout=widget->d_func()->layout) {
3283 layout->widgetEvent(e);
3284 }
3285 }
3286
3287 // send to all receiver event filters
3288 if (sendThroughObjectEventFilters(receiver, e)) {
3289 filtered = true;
3290 return filtered;
3291 }
3292
3293 // deliver the event
3294 consumed = receiver->event(e);
3295
3297 return consumed;
3298}
3299
3304
3306{
3308 qt_widget_private(QWidget::keyboardGrabber())->stealKeyboardGrab(true);
3309 else
3310 qt_widget_private(popup)->stealKeyboardGrab(false);
3311}
3312
3313static void ungrabMouseForPopup(QWidget *popup)
3314{
3316 qt_widget_private(QWidget::mouseGrabber())->stealMouseGrab(true);
3317 else
3318 qt_widget_private(popup)->stealMouseGrab(false);
3319}
3320
3321static bool popupGrabOk;
3322
3323static void grabForPopup(QWidget *popup)
3324{
3326 popupGrabOk = qt_widget_private(popup)->stealKeyboardGrab(true);
3327 if (popupGrabOk) {
3328 popupGrabOk = qt_widget_private(popup)->stealMouseGrab(true);
3329 if (!popupGrabOk) {
3330 // transfer grab back to the keyboard grabber if any
3332 }
3333 }
3334}
3335
3336extern QWidget *qt_popup_down;
3337extern bool qt_replay_popup_mouse_event;
3338extern bool qt_popup_down_closed;
3339
3341{
3342 // Close all popups: In case some popup refuses to close,
3343 // we give up after 1024 attempts (to avoid an infinite loop).
3344 int maxiter = 1024;
3345 QWidget *popup;
3346 while ((popup = QApplication::activePopupWidget()) && maxiter--)
3347 popup->close(); // this will call QApplicationPrivate::closePopup
3348 return true;
3349}
3350
3352{
3353 if (!popupWidgets)
3354 return;
3355 popupWidgets->removeAll(popup);
3356
3357 if (popup == qt_popup_down) {
3358 qt_button_down = nullptr;
3359 qt_popup_down_closed = true;
3360 qt_popup_down = nullptr;
3361 }
3362
3363 if (QApplicationPrivate::popupWidgets->size() == 0) { // this was the last popup
3366 qt_popup_down_closed = false;
3367
3368 if (popupGrabOk) {
3369 popupGrabOk = false;
3370
3371 // TODO on multi-seat window systems, we have to know which mouse
3373 auto mousePressPos = devPriv->pointById(0)->eventPoint.globalPressPosition();
3374 if (popup->geometry().contains(mousePressPos.toPoint())
3376 // mouse release event or inside
3378 } else { // mouse press event
3380 }
3381
3382 // transfer grab back to mouse grabber if any, otherwise release the grab
3383 ungrabMouseForPopup(popup);
3384
3385 // transfer grab back to keyboard grabber if any, otherwise release the grab
3387 }
3388
3389 if (active_window) {
3390 if (QWidget *fw = active_window->focusWidget()) {
3391 if (fw != QApplication::focusWidget()) {
3392 fw->setFocus(Qt::PopupFocusReason);
3393 } else {
3396 }
3397 }
3398 }
3399
3400 } else {
3401 // A popup was closed, so the previous popup gets the focus.
3402 QWidget* aw = QApplicationPrivate::popupWidgets->constLast();
3403 if (QWidget *fw = aw->focusWidget())
3404 fw->setFocus(Qt::PopupFocusReason);
3405
3406 // can become nullptr due to setFocus() above
3408 QApplicationPrivate::popupWidgets->size() == 1) // grab mouse/keyboard
3409 grabForPopup(aw);
3410 }
3411
3412}
3413
3415
3417{
3419 if (!popupWidgets) // create list
3421 popupWidgets->append(popup); // add to end of list
3422
3423 if (QApplicationPrivate::popupWidgets->size() == 1) // grab mouse/keyboard
3424 grabForPopup(popup);
3425
3426 // popups are not focus-handled by the window system (the first
3427 // popup grabbed the keyboard), so we have to do that manually: A
3428 // new popup gets the focus
3429 if (popup->focusWidget()) {
3431 } else if (popupWidgets->size() == 1) { // this was the first popup
3432 if (QWidget *fw = QApplication::focusWidget()) {
3435 }
3436 }
3437}
3438
3439#ifdef QT_KEYPAD_NAVIGATION
3447void QApplication::setNavigationMode(Qt::NavigationMode mode)
3448{
3449 QApplicationPrivate::navigationMode = mode;
3450}
3451
3459Qt::NavigationMode QApplication::navigationMode()
3460{
3461 return QApplicationPrivate::navigationMode;
3462}
3463#endif
3464
3488{
3489 if (widget) {
3491 return;
3493 window->alert(duration);
3494 } else {
3495 const auto topLevels = topLevelWidgets();
3496 for (QWidget *topLevel : topLevels)
3497 QApplication::alert(topLevel, duration);
3498 }
3499}
3500
3520{
3521 QGuiApplication::styleHints()->setCursorFlashTime(msecs);
3522}
3523
3525{
3526 return QGuiApplication::styleHints()->cursorFlashTime();
3527}
3528
3538{
3539 QGuiApplication::styleHints()->setMouseDoubleClickInterval(ms);
3540}
3541
3543{
3544 return QGuiApplication::styleHints()->mouseDoubleClickInterval();
3545}
3546
3557{
3558 QGuiApplication::styleHints()->setKeyboardInputInterval(ms);
3559}
3560
3562{
3563 return QGuiApplication::styleHints()->keyboardInputInterval();
3564}
3565
3583#if QT_CONFIG(wheelevent)
3584int QApplication::wheelScrollLines()
3585{
3586 return styleHints()->wheelScrollLines();
3587}
3588
3589void QApplication::setWheelScrollLines(int lines)
3590{
3591 styleHints()->setWheelScrollLines(lines);
3592}
3593#endif
3594
3615
3628{
3629 int effectFlags = uiEffectToFlag(effect);
3630 if (enable) {
3631 if (effectFlags & QPlatformTheme::FadeMenuUiEffect)
3633 if (effectFlags & QPlatformTheme::FadeTooltipUiEffect)
3636 } else {
3638 }
3639}
3640
3661
3672
3685{
3686 return QGuiApplication::sendSpontaneousEvent(receiver, event);
3687}
3688
3689void QApplicationPrivate::giveFocusAccordingToFocusPolicy(QWidget *widget, QEvent *event, QPoint localPos)
3690{
3691 const bool setFocusOnRelease = QGuiApplication::styleHints()->setFocusOnTouchRelease();
3692 Qt::FocusPolicy focusPolicy = Qt::ClickFocus;
3693 static QPointer<QWidget> focusedWidgetOnTouchBegin = nullptr;
3694
3695 switch (event->type()) {
3698 case QEvent::TouchBegin:
3699 focusedWidgetOnTouchBegin = QApplication::focusWidget();
3700 if (setFocusOnRelease)
3701 return;
3702 break;
3704 case QEvent::TouchEnd:
3705 if (!setFocusOnRelease)
3706 return;
3707 if (focusedWidgetOnTouchBegin != QApplication::focusWidget()) {
3708 // Focus widget was changed while delivering press/move events.
3709 // To not interfere with application logic, we leave focus as-is
3710 return;
3711 }
3712 break;
3713 case QEvent::Wheel:
3714 focusPolicy = Qt::WheelFocus;
3715 break;
3716 default:
3717 return;
3718 }
3719
3720 QWidget *focusWidget = widget;
3721 while (focusWidget) {
3722 if (focusWidget->isEnabled()
3723 && focusWidget->rect().contains(localPos)
3724 && QApplicationPrivate::shouldSetFocus(focusWidget, focusPolicy)) {
3725 focusWidget->setFocus(Qt::MouseFocusReason);
3726 break;
3727 }
3728 if (focusWidget->isWindow())
3729 break;
3730
3731 // find out whether this widget (or its proxy) already has focus
3732 QWidget *f = focusWidget;
3733 if (focusWidget->d_func()->extra && focusWidget->d_func()->extra->focus_proxy)
3734 f = focusWidget->d_func()->extra->focus_proxy;
3735 // if it has, stop here.
3736 // otherwise a click on the focused widget would remove its focus if ClickFocus isn't set
3737 if (f->hasFocus())
3738 break;
3739
3740 localPos += focusWidget->pos();
3741 focusWidget = focusWidget->parentWidget();
3742 }
3743}
3744
3745bool QApplicationPrivate::shouldSetFocus(QWidget *w, Qt::FocusPolicy policy)
3746{
3747 QWidget *f = w;
3748 while (f->d_func()->extra && f->d_func()->extra->focus_proxy)
3749 f = f->d_func()->extra->focus_proxy;
3750
3751 if ((w->focusPolicy() & policy) != policy)
3752 return false;
3753 if (w != f && (f->focusPolicy() & policy) != policy)
3754 return false;
3755 return true;
3756}
3757
3759{
3760 bool containsPress = false;
3761
3762 for (int i = 0; i < touchEvent->pointCount(); ++i) {
3763 auto &pt = touchEvent->point(i);
3764 QMutableEventPoint::setPosition(pt, widget->mapFromGlobal(pt.globalPosition()));
3765
3766 if (pt.state() == QEventPoint::State::Pressed)
3767 containsPress = true;
3768 }
3769 return containsPress;
3770}
3771
3776
3780
3785
3789
3791{
3792 const QPointF globalPos = touchPoint.globalPosition();
3793 int closestTouchPointId = -1;
3794 QObject *closestTarget = nullptr;
3795 qreal closestDistance = 0;
3797 for (auto &epd : devPriv->activePoints.values()) {
3798 const auto &pt = epd.eventPoint;
3799 if (pt.id() != touchPoint.id()) {
3800 qreal dx = globalPos.x() - pt.globalPosition().x();
3801 qreal dy = globalPos.y() - pt.globalPosition().y();
3802 qreal distance = dx * dx + dy * dy;
3803 if (closestTouchPointId == -1 || distance < closestDistance) {
3804 closestTouchPointId = pt.id();
3805 closestDistance = distance;
3806 closestTarget = QMutableEventPoint::target(pt);
3807 }
3808 }
3809 }
3810 return static_cast<QWidget *>(closestTarget);
3811}
3812
3814 ImplicitTouchGrabMode grabMode)
3815{
3816 if (touchEvent->type() != QEvent::TouchBegin)
3817 return;
3818
3819 // If the widget dispatched the event further (see QGraphicsProxyWidget), then
3820 // there might already be an implicit grabber. Don't override that. A widget that
3821 // has partially recognized a gesture needs to grab all points.
3822 for (int i = 0; i < touchEvent->pointCount(); ++i) {
3823 auto &ep = touchEvent->point(i);
3824 if (!QMutableEventPoint::target(ep) && (ep.isAccepted() || grabMode == GrabAllPoints))
3825 QMutableEventPoint::setTarget(ep, widget);
3826 }
3827 // TODO setExclusiveGrabber() to be consistent with Qt Quick?
3828}
3829
3831{
3832 QApplicationPrivate *d = self;
3833 // TODO get rid of this QPair
3834 typedef QPair<QEventPoint::State, QList<QEventPoint> > StatesAndTouchPoints;
3835 QHash<QWidget *, StatesAndTouchPoints> widgetsNeedingEvents;
3836
3837 const auto *device = te->pointingDevice();
3838 auto touchPoints = te->points(); // touch points will be mutated
3839 for (auto &touchPoint : touchPoints) {
3840 // update state
3841 QPointer<QObject> target;
3842 if (touchPoint.state() == QEventPoint::State::Pressed) {
3844 // on touchpads, send all touch points to the same widget:
3845 // pick the first non-null target if possible
3846 target = QPointingDevicePrivate::get(device)->firstActiveTarget();
3847 }
3848
3849 if (target.isNull()) {
3850 // determine which widget this event will go to
3851 if (!window)
3852 window = QApplication::topLevelAt(touchPoint.globalPosition().toPoint());
3853 if (!window)
3854 continue;
3855 target = window->childAt(window->mapFromGlobal(touchPoint.globalPosition().toPoint()));
3856 if (!target)
3857 target = window;
3858 }
3859
3860 bool usingClosestWidget = false;
3862 QWidget *closestWidget = d->findClosestTouchPointTarget(device, touchPoint);
3863 QWidget *widget = static_cast<QWidget *>(target.data());
3864 if (closestWidget
3865 && (widget->isAncestorOf(closestWidget) || closestWidget->isAncestorOf(widget))) {
3866 target = closestWidget;
3867 usingClosestWidget = true;
3868 }
3869 }
3870
3871 // on touch pads, implicitly grab all touch points
3872 // on touch screens, grab touch points that are redirected to the closest widget
3873 if (device->type() == QInputDevice::DeviceType::TouchPad || usingClosestWidget)
3874 QMutableEventPoint::setTarget(touchPoint, target);
3875 } else {
3876 target = QMutableEventPoint::target(touchPoint);
3877 if (!target)
3878 continue;
3879 }
3880 Q_ASSERT(!target.isNull());
3881
3882 QWidget *targetWidget = static_cast<QWidget *>(target.data());
3883
3884#ifdef Q_OS_MACOS
3885 // Single-touch events are normally not sent unless WA_TouchPadAcceptSingleTouchEvents is set.
3886 // In Qt 4 this check was in OS X-only code. That behavior is preserved here by the #ifdef.
3887 if (touchPoints.count() == 1
3890 continue;
3891#endif
3892
3893 StatesAndTouchPoints &maskAndPoints = widgetsNeedingEvents[targetWidget];
3894 maskAndPoints.first = QEventPoint::State(maskAndPoints.first | touchPoint.state());
3895 maskAndPoints.second.append(touchPoint);
3896 }
3897
3898 if (widgetsNeedingEvents.isEmpty())
3899 return false;
3900
3901 bool accepted = false;
3903 const QHash<QWidget *, StatesAndTouchPoints>::ConstIterator end = widgetsNeedingEvents.constEnd();
3904 for (; it != end; ++it) {
3905 const QPointer<QWidget> widget = it.key();
3907 continue;
3908
3909 QEvent::Type eventType;
3910 switch (it.value().first) {
3912 eventType = QEvent::TouchBegin;
3913 break;
3915 eventType = QEvent::TouchEnd;
3916 break;
3918 // don't send the event if nothing changed
3919 continue;
3920 default:
3921 eventType = QEvent::TouchUpdate;
3922 break;
3923 }
3924
3926 it.value().second);
3927 bool containsPress = updateTouchPointsForWidget(widget, &touchEvent);
3928 touchEvent.setTimestamp(te->timestamp());
3929 touchEvent.setTarget(widget);
3930
3931 if (containsPress)
3933
3934 switch (touchEvent.type()) {
3935 case QEvent::TouchBegin:
3936 {
3937 // if the TouchBegin handler recurses, we assume that means the event
3938 // has been implicitly accepted and continue to send touch events
3939 bool res = te->spontaneous() ? QApplication::sendSpontaneousEvent(widget, &touchEvent)
3940 : QApplication::sendEvent(widget, &touchEvent);
3941 if (res && touchEvent.isAccepted()) {
3942 accepted = true;
3943 if (!widget.isNull())
3945 }
3946 break;
3947 }
3948 default:
3950#ifndef QT_NO_GESTURES
3952#endif
3953 ) {
3954 bool res = te->spontaneous() ? QApplication::sendSpontaneousEvent(widget, &touchEvent)
3955 : QApplication::sendEvent(widget, &touchEvent);
3956 if (res && touchEvent.isAccepted())
3957 accepted = true;
3958 // widget can be deleted on TouchEnd
3959 if (touchEvent.type() == QEvent::TouchEnd && !widget.isNull())
3961 }
3962 break;
3963 }
3964 }
3965 return accepted;
3966}
3967
3969{
3971 touchEvent.setTimestamp(timestamp);
3972
3973 QSet<QWidget *> widgetsNeedingCancel;
3975 for (auto &epd : devPriv->activePoints.values()) {
3976 const auto &pt = epd.eventPoint;
3978 if (target && target->isWidgetType())
3979 widgetsNeedingCancel.insert(static_cast<QWidget *>(target));
3980 }
3981 for (QSet<QWidget *>::const_iterator widIt = widgetsNeedingCancel.constBegin(),
3982 widItEnd = widgetsNeedingCancel.constEnd(); widIt != widItEnd; ++widIt) {
3983 QWidget *widget = *widIt;
3984 touchEvent.setTarget(widget);
3985 QApplication::sendSpontaneousEvent(widget, &touchEvent);
3986 }
3987}
3988
3995
3996#if QT_CONFIG(draganddrop)
3997void QApplicationPrivate::notifyDragStarted(const QDrag *drag)
3998{
3999 QGuiApplicationPrivate::notifyDragStarted(drag);
4000 // QTBUG-26145
4001 // Prevent pickMouseReceiver() from using the widget where the drag was started after a drag operation...
4002 // QTBUG-56713
4003 // ...only if qt_button_down is not a QQuickWidget
4004 if (qt_button_down && !qt_button_down->inherits("QQuickWidget"))
4005 qt_button_down = nullptr;
4006}
4007#endif // QT_CONFIG(draganddrop)
4008
4009#ifndef QT_NO_GESTURES
4011{
4013 if (!qAppPriv)
4014 return nullptr;
4015 if (!qAppPriv->gestureManager && ic == ForceCreation)
4016 qAppPriv->gestureManager = new QGestureManager(qApp);
4017 return qAppPriv->gestureManager;
4018}
4019#endif // QT_NO_GESTURES
4020
4027
4028void *QApplication::resolveInterface(const char *name, int revision) const
4029{
4030 return QGuiApplication::resolveInterface(name, revision);
4031}
4032
4034
4035#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 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
QHash< QByteArray, QPalette > PaletteHash
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
The QContextMenuEvent class contains parameters that describe a context menu event.
Definition qevent.h:594
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
static QDragManager * self()
Definition qdnd.cpp:30
\inmodule QtGui
Definition qdrag.h:22
\inmodule QtGui
Definition qevent.h:165
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:43
int id
the ID number of this event point.
Definition qeventpoint.h:24
State
Specifies the state of this event point.
Definition qeventpoint.h:48
\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:305
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:304
void ignore()
Clears the accept flag parameter of the event object, the equivalent of calling setAccepted(false).
Definition qcoreevent.h:311
bool isAccepted() const
Definition qcoreevent.h:308
The QFocusEvent class contains event parameters for widget focus events.
Definition qevent.h:470
\reentrant \inmodule QtGui
\reentrant
Definition qfont.h:22
The QGestureEvent class provides the description of triggered gestures.
Definition qgesture.h:244
QList< QGesture * > gestures() const
Returns all gestures that are delivered in the event.
Definition qgesture.cpp:868
static bool gesturePending(QObject *o)
static QGestureManager * instance(InstanceCreation ic=ForceCreation)
QGestureManager(QObject *parent)
The QGesture class represents a gesture, containing properties that describe the corresponding user i...
Definition qgesture.h:29
Qt::GestureType gestureType
the type of the gesture
Definition qgesture.h:34
static QPlatformIntegration * platformIntegration()
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:1145
friend class const_iterator
Definition qhash.h:1182
The QHelpEvent class provides an event that is used to request helpful information about a particular...
Definition qevent.h:788
\inmodule QtGui
Definition qevent.h:246
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
The QKeyEvent class describes a key event.
Definition qevent.h:424
int count() const
Returns the number of keys involved in this event.
Definition qevent.h:445
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifier flags that existed immediately after the event occurred.
Definition qevent.cpp:1468
QString text() const
Returns the Unicode text that this key generated.
Definition qevent.h:443
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:444
int key() const
Returns the code of the key that was pressed or released.
Definition qevent.h:434
The QLayout class is the base class of geometry managers.
Definition qlayout.h:26
void widgetEvent(QEvent *)
Definition qlayout.cpp:520
const_iterator ConstIterator
Definition qlist.h:250
iterator find(const Key &key)
Definition qmap.h:641
iterator end()
Definition qmap.h:602
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:196
The QMoveEvent class contains event parameters for move events.
Definition qevent.h:502
const QPoint & pos() const
Returns the new position of the widget.
Definition qevent.h:507
static QObject * target(const QEventPoint &p)
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:73
\inmodule QtCore
Definition qobject.h:103
bool isWindowType() const
Returns true if the object is a window; otherwise returns false.
Definition qobject.h:132
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:346
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:1389
QThread * thread() const
Returns the thread in which the object lives.
Definition qobject.cpp:1598
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:348
bool isWidgetType() const
Returns true if the object is a widget; otherwise returns false.
Definition qobject.h:131
The QPalette class contains color groups for each widget state.
Definition qpalette.h:19
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
The QPlatformTheme class allows customizing the UI based on themes.
virtual const QFont * font(Font type=SystemFont) const
virtual bool isForeignWindow() const
\inmodule QtCore\reentrant
Definition qpoint.h:217
constexpr qreal x() const noexcept
Returns the x coordinate of this point.
Definition qpoint.h:343
constexpr qreal y() const noexcept
Returns the y coordinate of this point.
Definition qpoint.h:348
\inmodule QtCore\reentrant
Definition qpoint.h:25
void setTimestamp(quint64 timestamp) override
Definition qevent.cpp:338
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:484
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:1993
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:855
The QRegion class specifies a clip region for a painter.
Definition qregion.h:27
The QResizeEvent class contains event parameters for resize events.
Definition qevent.h:548
const QSize & size() const
Returns the new size of the widget.
Definition qevent.h:553
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
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
static QString fromLocal8Bit(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:5949
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
Definition qstring.h:192
static QStringList keys()
Returns the list of valid keys, i.e.
static QStyle * create(const QString &)
The QStyleOption class stores the parameters used by QStyle functions.
QPalette palette
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI.
Definition qstyle.h:29
@ SH_Widget_ShareActivation
Definition qstyle.h:608
@ SH_ToolTip_FallAsleepDelay
Definition qstyle.h:684
@ SH_ToolTip_WakeUpDelay
Definition qstyle.h:683
virtual int styleHint(StyleHint stylehint, const QStyleOption *opt=nullptr, const QWidget *widget=nullptr, QStyleHintReturn *returnData=nullptr) const =0
Returns an integer representing the specified style hint for the given widget described by the provid...
QEventPoint & point(int touchId)
QMap< int, QEventPoint > points
static QThread * currentThread()
Definition qthread.cpp:1039
\inmodule QtCore
Definition qcoreevent.h:366
static void setPalette(const QPalette &)
Definition qtooltip.cpp:558
The QTouchEvent class contains parameters that describe a touch event.
Definition qevent.h:917
const QRegion & region() const
Definition qwidget_p.h:82
static void enterWhatsThisMode()
This function switches the user interface into "What's This?" mode.
static int instanceCounter
Definition qwidget_p.h:701
QMap< Qt::GestureType, Qt::GestureFlags > gestureContext
Definition qwidget_p.h:712
static QWidgetMapper * mapper
Definition qwidget_p.h:661
static void setWidgetParentHelper(QObject *widgetAsObject, QObject *newParent)
static int maxInstances
Definition qwidget_p.h:702
static QWidgetSet * allWidgets
Definition qwidget_p.h:662
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:4313
WId internalWinId() const
Definition qwidget.h:220
void raise()
Raises this widget to the top of the parent widget's stack.
QWidget * nextInFocusChain() const
Returns the next widget in this widget's focus chain.
Definition qwidget.cpp:6845
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:8643
QPoint pos
the position of the widget within its parent widget
Definition qwidget.h:111
bool close()
Closes this widget.
Definition qwidget.cpp:8562
QWidget * focusWidget() const
Returns the last child of this widget that setFocus had been called on.
Definition qwidget.cpp:6828
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
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:2483
static QWidget * keyboardGrabber()
Returns the widget that is currently grabbing the keyboard input.
WId effectiveWinId() const
Definition qwidget.cpp:2462
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
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:2888
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:8822
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:4263
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:4960
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:106
\inmodule QtGui
Definition qwindow.h:63
QOpenGLWidget * widget
[1]
QHash< int, QWidget * > hash
[35multi]
QString text
bool focus
[0]
QSet< QString >::iterator it
QStyleOptionButton opt
short next
Definition keywords.cpp:445
Combined button and popup list for selecting options.
@ WindowMinimized
Definition qnamespace.h:253
NavigationMode
@ NavigationModeKeypadTabOrder
@ TabFocusAllControls
Definition qnamespace.h:118
@ NoButton
Definition qnamespace.h:57
@ WA_AcceptTouchEvents
Definition qnamespace.h:404
@ WA_UnderMouse
Definition qnamespace.h:284
@ WA_TouchPadAcceptSingleTouchEvents
Definition qnamespace.h:406
@ WA_TransparentForMouseEvents
Definition qnamespace.h:317
@ WA_MacMiniSize
Definition qnamespace.h:363
@ WA_SetLocale
Definition qnamespace.h:358
@ WA_AlwaysShowToolTips
Definition qnamespace.h:354
@ WA_SetCursor
Definition qnamespace.h:305
@ WA_Hover
Definition qnamespace.h:340
@ WA_WState_Polished
Definition qnamespace.h:332
@ WA_DontShowOnScreen
Definition qnamespace.h:383
@ WA_NoMouseReplay
Definition qnamespace.h:320
@ WA_KeyboardFocusChange
Definition qnamespace.h:344
@ WA_SetStyle
Definition qnamespace.h:356
@ WA_NoMousePropagation
Definition qnamespace.h:339
@ WA_WState_AcceptedTouchBeginEvent
Definition qnamespace.h:405
@ WA_WState_Created
Definition qnamespace.h:327
@ WA_MacSmallSize
Definition qnamespace.h:362
@ WA_InputMethodEnabled
Definition qnamespace.h:295
WindowModality
@ ApplicationModal
@ GestureStarted
FocusPolicy
Definition qnamespace.h:106
@ WheelFocus
Definition qnamespace.h:111
@ ClickFocus
Definition qnamespace.h:109
@ NoFocus
Definition qnamespace.h:107
@ TabFocus
Definition qnamespace.h:108
@ StrongFocus
Definition qnamespace.h:110
@ gray
Definition qnamespace.h:33
@ UI_AnimateToolBox
@ UI_FadeMenu
@ UI_AnimateCombo
@ UI_General
@ UI_AnimateTooltip
@ UI_AnimateMenu
@ UI_FadeTooltip
@ Key_Tab
Definition qnamespace.h:664
@ Key_Right
Definition qnamespace.h:679
@ Key_Backtab
Definition qnamespace.h:665
@ Key_Left
Definition qnamespace.h:677
@ Key_Up
Definition qnamespace.h:678
@ Key_Down
Definition qnamespace.h:680
@ NoModifier
@ AA_SetPalette
Definition qnamespace.h:448
@ AA_NativeWindows
Definition qnamespace.h:428
@ CaseInsensitive
GestureType
@ ReceivePartialGestures
ScrollPhase
@ ScrollBegin
@ ScrollUpdate
@ ScrollMomentum
@ NoScrollPhase
@ ScrollEnd
@ Desktop
Definition qnamespace.h:215
@ Popup
Definition qnamespace.h:211
@ Dialog
Definition qnamespace.h:208
@ SubWindow
Definition qnamespace.h:216
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()
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:5014
#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)
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:283
#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:164
#define qWarning
Definition qlogging.h:166
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
GLdouble s
[6]
Definition qopenglext.h:235
GLuint res
GLuint in
GLuint64EXT * result
[6]
GLfloat GLfloat p
[1]
static void initResources()
Definition qpdf.cpp:39
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
SSL_CTX int void * arg
#define qPrintable(string)
Definition qstring.h:1531
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:35
unsigned int uint
Definition qtypes.h:34
unsigned short ushort
Definition qtypes.h:33
double qreal
Definition qtypes.h:187
static const uint base
Definition qurlidna.cpp:20
#define leave(x)
Q_WIDGETS_EXPORT QWidgetPrivate * qt_widget_private(QWidget *widget)
#define QWIDGETSIZE_MAX
Definition qwidget.h:917
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