diff options
Diffstat (limited to 'src/widgets/kernel')
-rw-r--r-- | src/widgets/kernel/qaction.cpp | 5 | ||||
-rw-r--r-- | src/widgets/kernel/qactiongroup.cpp | 96 | ||||
-rw-r--r-- | src/widgets/kernel/qactiongroup.h | 11 | ||||
-rw-r--r-- | src/widgets/kernel/qapplication.cpp | 59 | ||||
-rw-r--r-- | src/widgets/kernel/qdesktopwidget.cpp | 12 | ||||
-rw-r--r-- | src/widgets/kernel/qopenglwidget.cpp | 7 | ||||
-rw-r--r-- | src/widgets/kernel/qwidget.cpp | 131 | ||||
-rw-r--r-- | src/widgets/kernel/qwidget_p.h | 19 | ||||
-rw-r--r-- | src/widgets/kernel/qwidgetwindow.cpp | 5 |
9 files changed, 216 insertions, 129 deletions
diff --git a/src/widgets/kernel/qaction.cpp b/src/widgets/kernel/qaction.cpp index 1ca5514655..f6631199d6 100644 --- a/src/widgets/kernel/qaction.cpp +++ b/src/widgets/kernel/qaction.cpp @@ -1153,8 +1153,9 @@ void QAction::activate(ActionEvent event) if(event == Trigger) { QPointer<QObject> guard = this; if(d->checkable) { - // the checked action of an exclusive group cannot be unchecked - if (d->checked && (d->group && d->group->isExclusive() + // the checked action of an exclusive group may not be unchecked + if (d->checked && (d->group + && d->group->exclusionPolicy() == QActionGroup::ExclusionPolicy::Exclusive && d->group->checkedAction() == this)) { if (!guard.isNull()) emit triggered(true); diff --git a/src/widgets/kernel/qactiongroup.cpp b/src/widgets/kernel/qactiongroup.cpp index 4786437d7e..ab42b1c7aa 100644 --- a/src/widgets/kernel/qactiongroup.cpp +++ b/src/widgets/kernel/qactiongroup.cpp @@ -52,12 +52,16 @@ class QActionGroupPrivate : public QObjectPrivate { Q_DECLARE_PUBLIC(QActionGroup) public: - QActionGroupPrivate() : exclusive(1), enabled(1), visible(1) { } + QActionGroupPrivate() : enabled(1), + visible(1), + exclusionPolicy(QActionGroup::ExclusionPolicy::Exclusive) + { + } QList<QAction *> actions; QPointer<QAction> current; - uint exclusive : 1; uint enabled : 1; uint visible : 1; + QActionGroup::ExclusionPolicy exclusionPolicy; private: void _q_actionTriggered(); //private slot @@ -70,7 +74,7 @@ void QActionGroupPrivate::_q_actionChanged() Q_Q(QActionGroup); QAction *action = qobject_cast<QAction*>(q->sender()); Q_ASSERT_X(action != 0, "QWidgetGroup::_q_actionChanged", "internal error"); - if(exclusive) { + if (exclusionPolicy != QActionGroup::ExclusionPolicy::None) { if (action->isChecked()) { if (action != current) { if(current) @@ -127,12 +131,17 @@ void QActionGroupPrivate::_q_actionHovered() actions is chosen. Each action in an action group emits its triggered() signal as usual. - As stated above, an action group is \l exclusive by default; it - ensures that only one checkable action is active at any one time. + As stated above, an action group is exclusive by default; it + ensures that at most only one checkable action is active at any one time. If you want to group checkable actions without making them - exclusive, you can turn of exclusiveness by calling + exclusive, you can turn off exclusiveness by calling setExclusive(false). + By default the active action of an exclusive group cannot be unchecked. + In some cases it may be useful to allow unchecking all the actions, + you can allow this by calling + setExclusionPolicy(QActionGroup::ExclusionPolicy::ExclusiveOptional). + Actions can be added to an action group using addAction(), but it is usually more convenient to specify a group when creating actions; this ensures that actions are automatically created with @@ -146,10 +155,33 @@ void QActionGroupPrivate::_q_actionHovered() */ /*! + \enum QActionGroup::ExclusionPolicy + + This enum specifies the different policies that can be used to + control how the group performs exclusive checking on checkable actions. + + \value None + The actions in the group can be checked independently of each other. + + \value Exclusive + Exactly one action can be checked at any one time. + This is the default policy. + + \value ExclusiveOptional + At most one action can be checked at any one time. The actions + can also be all unchecked. + + \sa exclusionPolicy + \since 5.14 +*/ + +/*! Constructs an action group for the \a parent object. The action group is exclusive by default. Call setExclusive(false) - to make the action group non-exclusive. + to make the action group non-exclusive. To make the group exclusive + but allow unchecking the active action call instead + setExclusionPolicy(QActionGroup::ExclusionPolicy::ExclusiveOptional) */ QActionGroup::QActionGroup(QObject* parent) : QObject(*new QActionGroupPrivate, parent) { @@ -258,26 +290,56 @@ QList<QAction*> QActionGroup::actions() const } /*! - \property QActionGroup::exclusive - \brief whether the action group does exclusive checking + \brief Enable or disable the group exclusion checking - If exclusive is true, only one checkable action in the action group - can ever be active at any time. If the user chooses another - checkable action in the group, the one they chose becomes active and - the one that was active becomes inactive. + This is a convenience method that calls + setExclusionPolicy(ExclusionPolicy::Exclusive). - \sa QAction::checkable + \sa QActionGroup::exclusionPolicy */ void QActionGroup::setExclusive(bool b) { - Q_D(QActionGroup); - d->exclusive = b; + setExclusionPolicy(b ? QActionGroup::ExclusionPolicy::Exclusive + : QActionGroup::ExclusionPolicy::None); } +/*! + \brief Returs true if the group is exclusive + + The group is exclusive if the ExclusionPolicy is either Exclusive + or ExclusionOptional. + +*/ bool QActionGroup::isExclusive() const { + return exclusionPolicy() != QActionGroup::ExclusionPolicy::None; +} + +/*! + \property QActionGroup::exclusionPolicy + \brief This property holds the group exclusive checking policy + + If exclusionPolicy is set to Exclusive, only one checkable + action in the action group can ever be active at any time. If the user + chooses another checkable action in the group, the one they chose becomes + active and the one that was active becomes inactive. If exclusionPolicy is + set to ExclusionOptional the group is exclusive but the active checkable + action in the group can be unchecked leaving the group with no actions + checked. + + \sa QAction::checkable + \since 5.14 +*/ +void QActionGroup::setExclusionPolicy(QActionGroup::ExclusionPolicy policy) +{ + Q_D(QActionGroup); + d->exclusionPolicy = policy; +} + +QActionGroup::ExclusionPolicy QActionGroup::exclusionPolicy() const +{ Q_D(const QActionGroup); - return d->exclusive; + return d->exclusionPolicy; } /*! diff --git a/src/widgets/kernel/qactiongroup.h b/src/widgets/kernel/qactiongroup.h index 61c90b911d..90f488bedb 100644 --- a/src/widgets/kernel/qactiongroup.h +++ b/src/widgets/kernel/qactiongroup.h @@ -55,11 +55,18 @@ class Q_WIDGETS_EXPORT QActionGroup : public QObject Q_OBJECT Q_DECLARE_PRIVATE(QActionGroup) - Q_PROPERTY(bool exclusive READ isExclusive WRITE setExclusive) + Q_PROPERTY(QActionGroup::ExclusionPolicy exclusionPolicy READ exclusionPolicy WRITE setExclusionPolicy) Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled) Q_PROPERTY(bool visible READ isVisible WRITE setVisible) public: + enum class ExclusionPolicy { + None, + Exclusive, + ExclusiveOptional + }; + Q_ENUM(ExclusionPolicy) + explicit QActionGroup(QObject* parent); ~QActionGroup(); @@ -73,6 +80,7 @@ public: bool isExclusive() const; bool isEnabled() const; bool isVisible() const; + ExclusionPolicy exclusionPolicy() const; public Q_SLOTS: @@ -80,6 +88,7 @@ public Q_SLOTS: inline void setDisabled(bool b) { setEnabled(!b); } void setVisible(bool); void setExclusive(bool); + void setExclusionPolicy(ExclusionPolicy policy); Q_SIGNALS: void triggered(QAction *); diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp index ba8878be57..526bf0a0ff 100644 --- a/src/widgets/kernel/qapplication.cpp +++ b/src/widgets/kernel/qapplication.cpp @@ -381,8 +381,6 @@ QWidget *QApplication::topLevelAt(const QPoint &pos) 0 if there is no such widget. */ -void qt_init(QApplicationPrivate *priv, int type - ); void qt_init_tooltip_palette(); void qt_cleanup(); @@ -428,16 +426,10 @@ bool Q_WIDGETS_EXPORT qt_tab_all_widgets() // ######## move to QApplicationPrivate // Default application palettes and fonts (per widget type) Q_GLOBAL_STATIC(PaletteHash, app_palettes) -PaletteHash *qt_app_palettes_hash() -{ - return app_palettes(); -} - Q_GLOBAL_STATIC(FontHash, app_fonts) -FontHash *qt_app_fonts_hash() -{ - return app_fonts(); -} +// Exported accessors for use outside of this file +PaletteHash *qt_app_palettes_hash() { return app_palettes(); } +FontHash *qt_app_fonts_hash() { return app_fonts(); } QWidgetList *QApplicationPrivate::popupWidgets = 0; // has keyboard input focus @@ -571,7 +563,10 @@ void QApplicationPrivate::init() process_cmdline(); // Must be called before initialize() - qt_init(this, application_type); + QColormap::initialize(); + qt_init_tooltip_palette(); + QApplicationPrivate::initializeWidgetFontHash(); + initialize(); eventDispatcher->startingUp(); @@ -582,18 +577,6 @@ void QApplicationPrivate::init() } -void qt_init(QApplicationPrivate *priv, int type) -{ - Q_UNUSED(priv); - Q_UNUSED(type); - - QColormap::initialize(); - - qt_init_tooltip_palette(); - - QApplicationPrivate::initializeWidgetFontHash(); -} - void qt_init_tooltip_palette() { #ifndef QT_NO_TOOLTIP @@ -659,7 +642,7 @@ void QApplicationPrivate::initializeWidgetPaletteHash() QPlatformTheme *platformTheme = QGuiApplicationPrivate::platformTheme(); if (!platformTheme) return; - qt_app_palettes_hash()->clear(); + app_palettes()->clear(); setPossiblePalette(platformTheme->palette(QPlatformTheme::ToolButtonPalette), "QToolButton"); setPossiblePalette(platformTheme->palette(QPlatformTheme::ButtonPalette), "QAbstractButton"); @@ -683,7 +666,7 @@ void QApplicationPrivate::initializeWidgetFontHash() const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme(); if (!theme) return; - FontHash *fontHash = qt_app_fonts_hash(); + FontHash *fontHash = app_fonts(); fontHash->clear(); if (const QFont *font = theme->font(QPlatformTheme::MenuFont)) @@ -1162,9 +1145,7 @@ void QApplication::setStyle(QStyle *style) } else if (QApplicationPrivate::sys_pal) { clearSystemPalette(); initSystemPalette(); - QApplicationPrivate::initializeWidgetPaletteHash(); QApplicationPrivate::initializeWidgetFontHash(); - QApplicationPrivate::setPalette_helper(*QApplicationPrivate::sys_pal, /*className=*/0, /*clearWidgetPaletteHash=*/false); } else if (!QApplicationPrivate::sys_pal) { // Initialize the sys_pal if it hasn't happened yet... QApplicationPrivate::setSystemPalette(QApplicationPrivate::app_style->standardPalette()); @@ -1462,28 +1443,10 @@ void QApplication::setPalette(const QPalette &palette, const char* className) void QApplicationPrivate::setSystemPalette(const QPalette &pal) { - QPalette adjusted; - -#if 0 - // adjust the system palette to avoid dithering - QColormap cmap = QColormap::instance(); - if (cmap.depths() > 4 && cmap.depths() < 24) { - for (int g = 0; g < QPalette::NColorGroups; g++) - for (int i = 0; i < QPalette::NColorRoles; i++) { - QColor color = pal.color((QPalette::ColorGroup)g, (QPalette::ColorRole)i); - color = cmap.colorAt(cmap.pixel(color)); - adjusted.setColor((QPalette::ColorGroup)g, (QPalette::ColorRole) i, color); - } - } -#else - adjusted = pal; -#endif - if (!sys_pal) - sys_pal = new QPalette(adjusted); + sys_pal = new QPalette(pal); else - *sys_pal = adjusted; - + *sys_pal = pal; if (!QApplicationPrivate::set_pal) QApplication::setPalette(*sys_pal); diff --git a/src/widgets/kernel/qdesktopwidget.cpp b/src/widgets/kernel/qdesktopwidget.cpp index d17c7eb36c..ac0cfcf2f5 100644 --- a/src/widgets/kernel/qdesktopwidget.cpp +++ b/src/widgets/kernel/qdesktopwidget.cpp @@ -321,20 +321,12 @@ int QDesktopWidgetPrivate::screenNumber(const QWidget *w) if (screens.isEmpty()) // This should never happen return primaryScreen(); - const QWindow *winHandle = w->windowHandle(); - if (!winHandle) { - if (const QWidget *nativeParent = w->nativeParentWidget()) - winHandle = nativeParent->windowHandle(); - } - // If there is more than one virtual desktop if (screens.count() != screens.constFirst()->virtualSiblings().count()) { // Find the root widget, get a QScreen from it and use the // virtual siblings for checking the window position. - if (winHandle) { - if (const QScreen *winScreen = winHandle->screen()) - screens = winScreen->virtualSiblings(); - } + if (const QScreen *winScreen = qt_widget_private(const_cast<QWidget *>(w))->associatedScreen()) + screens = winScreen->virtualSiblings(); } // Get the screen number from window position using screen geometry diff --git a/src/widgets/kernel/qopenglwidget.cpp b/src/widgets/kernel/qopenglwidget.cpp index 374ea53726..ae7729b49b 100644 --- a/src/widgets/kernel/qopenglwidget.cpp +++ b/src/widgets/kernel/qopenglwidget.cpp @@ -1333,11 +1333,8 @@ int QOpenGLWidget::metric(QPaintDevice::PaintDeviceMetric metric) const if (d->inBackingStorePaint) return QWidget::metric(metric); - QWidget *tlw = window(); - QWindow *window = tlw ? tlw->windowHandle() : 0; - QScreen *screen = tlw && tlw->windowHandle() ? tlw->windowHandle()->screen() : 0; - if (!screen && QGuiApplication::primaryScreen()) - screen = QGuiApplication::primaryScreen(); + auto window = d->windowHandle(QWidgetPrivate::WindowHandleMode::TopLevel); + QScreen *screen = window ? window->screen() : QGuiApplication::primaryScreen(); const float dpmx = qt_defaultDpiX() * 100. / 2.54; const float dpmy = qt_defaultDpiY() * 100. / 2.54; diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 8f927e8bee..2176c612d0 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -1,4 +1,4 @@ -/**************************************************************************** +/**************************************************************************** ** ** Copyright (C) 2017 The Qt Company Ltd. ** Copyright (C) 2016 Intel Corporation. @@ -79,6 +79,7 @@ #include "private/qstylesheetstyle_p.h" #include "private/qstyle_p.h" #include "qfileinfo.h" +#include "qscopeguard.h" #include <QtGui/private/qhighdpiscaling_p.h> #include <QtGui/qinputmethod.h> #include <QtGui/qopenglcontext.h> @@ -1123,6 +1124,8 @@ void QWidgetPrivate::adjustFlags(Qt::WindowFlags &flags, QWidget *w) void QWidgetPrivate::init(QWidget *parentWidget, Qt::WindowFlags f) { Q_Q(QWidget); + Q_ASSERT_X(q != parentWidget, Q_FUNC_INFO, "Cannot parent a QWidget to itself"); + if (Q_UNLIKELY(!qobject_cast<QApplication *>(QCoreApplication::instance()))) qFatal("QWidget: Cannot create a QWidget without QApplication"); @@ -1249,6 +1252,33 @@ void QWidgetPrivate::createRecursively() } } +QWindow *QWidgetPrivate::windowHandle(WindowHandleMode mode) const +{ + if (mode == WindowHandleMode::Direct || mode == WindowHandleMode::Closest) { + if (QTLWExtra *x = maybeTopData()) + return x->window; + } + if (mode == WindowHandleMode::Closest) { + if (auto nativeParent = q_func()->nativeParentWidget()) { + if (auto window = nativeParent->windowHandle()) + return window; + } + } + if (mode == WindowHandleMode::TopLevel || mode == WindowHandleMode::Closest) { + if (auto topLevel = q_func()->topLevelWidget()) { + if (auto window = topLevel ->windowHandle()) + return window; + } + } + return nullptr; +} + +QScreen *QWidgetPrivate::associatedScreen() const +{ + if (auto window = windowHandle(WindowHandleMode::Closest)) + return window->screen(); + return nullptr; +} // ### fixme: Qt 6: Remove parameter window from QWidget::create() @@ -2587,14 +2617,27 @@ bool QWidgetPrivate::setScreenForPoint(const QPoint &pos) Q_Q(QWidget); if (!q->isWindow()) return false; - // Find the screen for pos and make the widget undertand it is on that screen. + // Find the screen for pos and make the widget understand it is on that screen. + return setScreen(QGuiApplication::screenAt(pos)); +} + +/*! +\internal +Ensures that the widget's QWindow is set to be on the given \a screen. +Returns true if the screen was changed. +*/ + +bool QWidgetPrivate::setScreen(QScreen *screen) +{ + Q_Q(QWidget); + if (!screen || !q->isWindow()) + return false; const QScreen *currentScreen = windowHandle() ? windowHandle()->screen() : nullptr; - QScreen *actualScreen = QGuiApplication::screenAt(pos); - if (actualScreen && currentScreen != actualScreen) { + if (currentScreen != screen) { if (!windowHandle()) // Try to create a window handle if not created. createWinId(); if (windowHandle()) - windowHandle()->setScreen(actualScreen); + windowHandle()->setScreen(screen); return true; } return false; @@ -6995,37 +7038,41 @@ void QWidget::setTabOrder(QWidget* first, QWidget *second) lastFocusChild = focusNext; } }; + auto setPrev = [](QWidget *w, QWidget *prev) + { + w->d_func()->focus_prev = prev; + }; + auto setNext = [](QWidget *w, QWidget *next) + { + w->d_func()->focus_next = next; + }; - QWidget *lastFocusChildOfFirst, *lastFocusChildOfSecond; - determineLastFocusChild(first, lastFocusChildOfFirst); + // remove the second widget from the chain + QWidget *lastFocusChildOfSecond; determineLastFocusChild(second, lastFocusChildOfSecond); - - // If the tab order is already correct, exit early - if (lastFocusChildOfFirst == second || - lastFocusChildOfFirst->d_func()->focus_next == second) { - return; + { + QWidget *oldPrev = second->d_func()->focus_prev; + QWidget *prevWithFocus = oldPrev; + while (prevWithFocus->focusPolicy() == Qt::NoFocus) + prevWithFocus = prevWithFocus->d_func()->focus_prev; + // only widgets between first and second -> all is fine + if (prevWithFocus == first) + return; + QWidget *oldNext = lastFocusChildOfSecond->d_func()->focus_next; + setPrev(oldNext, oldPrev); + setNext(oldPrev, oldNext); } - // Note that we need to handle two different sections in the tab chain; The section - // that 'first' belongs to (firstSection), where we are about to insert 'second', and - // the section that 'second' used be a part of (secondSection). When we pull 'second' - // out of the second section and insert it into the first, we also need to ensure - // that we leave the second section in a connected state. - QWidget *firstChainOldSecond = lastFocusChildOfFirst->d_func()->focus_next; - QWidget *secondChainNewFirst = second->d_func()->focus_prev; - QWidget *secondChainNewSecond = lastFocusChildOfSecond->d_func()->focus_next; - - // Insert 'second' after 'first' - lastFocusChildOfFirst->d_func()->focus_next = second; - second->d_func()->focus_prev = lastFocusChildOfFirst; - - // The widget that used to be 'second' in the first section, should now become 'third' - lastFocusChildOfSecond->d_func()->focus_next = firstChainOldSecond; - firstChainOldSecond->d_func()->focus_prev = lastFocusChildOfSecond; - - // Repair the second section after we pulled 'second' out of it - secondChainNewFirst->d_func()->focus_next = secondChainNewSecond; - secondChainNewSecond->d_func()->focus_prev = secondChainNewFirst; + // insert the second widget into the chain + QWidget *lastFocusChildOfFirst; + determineLastFocusChild(first, lastFocusChildOfFirst); + { + QWidget *oldNext = lastFocusChildOfFirst->d_func()->focus_next; + setPrev(second, lastFocusChildOfFirst); + setNext(lastFocusChildOfFirst, second); + setPrev(oldNext, lastFocusChildOfSecond); + setNext(lastFocusChildOfSecond, oldNext); + } } /*!\internal @@ -8100,7 +8147,7 @@ void QWidgetPrivate::show_sys() { Q_Q(QWidget); - QWidgetWindow *window = windowHandle(); + auto window = qobject_cast<QWidgetWindow *>(windowHandle()); if (q->testAttribute(Qt::WA_DontShowOnScreen)) { invalidateBackingStore(q->rect()); @@ -8239,7 +8286,7 @@ void QWidgetPrivate::hide_sys() { Q_Q(QWidget); - QWidgetWindow *window = windowHandle(); + auto window = qobject_cast<QWidgetWindow *>(windowHandle()); if (q->testAttribute(Qt::WA_DontShowOnScreen)) { q->setAttribute(Qt::WA_Mapped, false); @@ -10677,6 +10724,22 @@ static void sendWindowChangeToTextureChildrenRecursively(QWidget *widget) void QWidget::setParent(QWidget *parent, Qt::WindowFlags f) { Q_D(QWidget); + Q_ASSERT_X(this != parent, Q_FUNC_INFO, "Cannot parent a QWidget to itself"); +#ifdef QT_DEBUG + const auto checkForParentChildLoops = qScopeGuard([&](){ + int depth = 0; + auto p = parentWidget(); + while (p) { + if (++depth == QObjectPrivate::CheckForParentChildLoopsWarnDepth) { + qWarning("QWidget %p (class: '%s', object name: '%s') may have a loop in its parent-child chain; " + "this is undefined behavior", + this, metaObject()->className(), qPrintable(objectName())); + } + p = p->parentWidget(); + } + }); +#endif + bool resized = testAttribute(Qt::WA_Resized); bool wasCreated = testAttribute(Qt::WA_WState_Created); QWidget *oldtlw = window(); diff --git a/src/widgets/kernel/qwidget_p.h b/src/widgets/kernel/qwidget_p.h index c073b8fb03..99ec38e050 100644 --- a/src/widgets/kernel/qwidget_p.h +++ b/src/widgets/kernel/qwidget_p.h @@ -181,6 +181,7 @@ struct QTLWExtra { QRect frameStrut; QRect normalGeometry; // used by showMin/maximized/FullScreen Qt::WindowFlags savedFlags; // Save widget flags while showing fullscreen + // ### TODO replace initialScreenIndex with QScreen *, in case the screens change at runtime int initialScreenIndex; // Screen number when passing a QDesktop[Screen]Widget as parent. QVector<QPlatformTextureList *> widgetTextures; @@ -342,7 +343,15 @@ public: QPainter *sharedPainter() const; void setSharedPainter(QPainter *painter); QWidgetBackingStore *maybeBackingStore() const; - QWidgetWindow *windowHandle() const; + + enum class WindowHandleMode { + Direct, + Closest, + TopLevel + }; + QWindow *windowHandle(WindowHandleMode mode = WindowHandleMode::Direct) const; + + QScreen *associatedScreen() const; template <typename T> void repaint(T t); @@ -356,6 +365,7 @@ public: void createWinId(); bool setScreenForPoint(const QPoint &pos); + bool setScreen(QScreen *screen); void createTLExtra(); void createExtra(); @@ -1014,13 +1024,6 @@ inline QWidgetBackingStore *QWidgetPrivate::maybeBackingStore() const return x ? x->backingStoreTracker.data() : nullptr; } -inline QWidgetWindow *QWidgetPrivate::windowHandle() const -{ - if (QTLWExtra *x = maybeTopData()) - return x->window; - return nullptr; -} - QT_END_NAMESPACE #endif // QWIDGET_P_H diff --git a/src/widgets/kernel/qwidgetwindow.cpp b/src/widgets/kernel/qwidgetwindow.cpp index 70b305326c..a5d9eee49d 100644 --- a/src/widgets/kernel/qwidgetwindow.cpp +++ b/src/widgets/kernel/qwidgetwindow.cpp @@ -592,10 +592,7 @@ void QWidgetWindow::handleMouseEvent(QMouseEvent *event) w->window()->raise(); } - QWindow *win = w->windowHandle(); - if (!win) - win = w->nativeParentWidget()->windowHandle(); - if (win) { + if (auto win = qt_widget_private(w)->windowHandle(QWidgetPrivate::WindowHandleMode::Closest)) { const QRect globalGeometry = win->isTopLevel() ? win->geometry() : QRect(win->mapToGlobal(QPoint(0, 0)), win->size()); |