diff options
author | Tor Arne Vestbø <[email protected]> | 2024-02-29 13:16:12 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <[email protected]> | 2024-03-03 10:26:11 +0000 |
commit | 04e05c59d60b40c1a1065e1e73bfb0ede9f942ce (patch) | |
tree | fbf70d39b79e31cecbee4650a0e20ea159f86382 | |
parent | 3ccc2b2b5f0d53f0f20ede9192d74855ad00d3f1 (diff) |
Add QWidgetPrivate::closestParentWidgetWithWindowHandle helper method
In contrast to nativeParentWidget(), we return the closest widget with a
QWindow, even if this window has not been created yet.
Pick-to: 6.5
Change-Id: Icac46297a6052a7a5698d752d4aa871bd5c2bdd8
Reviewed-by: Axel Spoerl <[email protected]>
(cherry picked from commit b571634172428263fa83ac733cf89e664bded014)
Reviewed-by: Qt Cherry-pick Bot <[email protected]>
(cherry picked from commit 0c519efa110ea298167e58774e220894a856fb78)
-rw-r--r-- | src/widgets/kernel/qwidget.cpp | 18 | ||||
-rw-r--r-- | src/widgets/kernel/qwidget_p.h | 2 |
2 files changed, 20 insertions, 0 deletions
diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 73f9722f1ad..acc97891f00 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -1021,6 +1021,23 @@ void QWidgetPrivate::createRecursively() } } +/*! + \internal + Returns the closest parent widget that has a QWindow window handle + + \note This behavior is different from nativeParentWidget(), which + returns the closest parent that has a QWindow window handle with + a created QPlatformWindow, and hence native window (winId). +*/ +QWidget *QWidgetPrivate::closestParentWidgetWithWindowHandle() const +{ + Q_Q(const QWidget); + QWidget *parent = q->parentWidget(); + while (parent && !parent->windowHandle()) + parent = parent->parentWidget(); + return parent; +} + QWindow *QWidgetPrivate::windowHandle(WindowHandleMode mode) const { if (mode == WindowHandleMode::Direct || mode == WindowHandleMode::Closest) { @@ -1030,6 +1047,7 @@ QWindow *QWidgetPrivate::windowHandle(WindowHandleMode mode) const } } if (mode == WindowHandleMode::Closest) { + // FIXME: Use closestParentWidgetWithWindowHandle instead if (auto nativeParent = q_func()->nativeParentWidget()) { if (auto window = nativeParent->windowHandle()) return window; diff --git a/src/widgets/kernel/qwidget_p.h b/src/widgets/kernel/qwidget_p.h index 8a86b069a0e..942fbf2235d 100644 --- a/src/widgets/kernel/qwidget_p.h +++ b/src/widgets/kernel/qwidget_p.h @@ -635,6 +635,8 @@ public: std::string flagsForDumping() const override; + QWidget *closestParentWidgetWithWindowHandle() const; + // Variables. // Regular pointers (keep them together to avoid gaps on 64 bit architectures). std::unique_ptr<QWExtra> extra; |