diff options
| author | Axel Spoerl <axel.spoerl@qt.io> | 2024-01-25 17:07:34 +0100 |
|---|---|---|
| committer | Axel Spoerl <axel.spoerl@qt.io> | 2024-03-07 23:00:33 +0000 |
| commit | 78a3301372fb9b48dc65b18a19731db37abab75c (patch) | |
| tree | 2a8ea29d299e726a224ecd608b142c650bef4cbc /src/widgets/kernel/qwidget.cpp | |
| parent | 8a6d9ac7bcd3ac3dfba1c9efdb9487ce48b28c9c (diff) | |
QDialogButtonBox: Don't set focus in a dialog with StrongFocus children
A QDialogButtonBox with the first accept button becoming default, didn't
explicitly set focus on such a button in a QDialog.
d44413d526ec12ed83acd7343c2005782178c7ad implemented this missing
functionality. It set focus to the automatic default button, unless the
QDialog had a focusWidget() set.
That has caused a regression, in cases where
- the QDialog has a QWidget child with a Qt::StrongFocus policy, and
- the QDialog is not yet visible, so focusWidget() returns nullptr.
Amend d44413d526ec12ed83acd7343c2005782178c7ad:
Implement a helper in QWidgetPrivate, that returns true, if a child
with a given focus policy is found.
Do not set focus to a QDialogButtonBox's automatic default button, when
- not located inside a QDialog, or
- a focusWidget() exists, or
- the dialog has QWidget child with Qt::StrongFocus, that is not a
child of the QDialogButtonBox.
Add an autotest function.
Pick-to: 6.7 6.6 6.5
Fixes: QTBUG-121514
Fixes: QTBUG-120049
Change-Id: I3c65ae36b56657f9af4a3a4b42f9b66e8bc5c534
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/widgets/kernel/qwidget.cpp')
| -rw-r--r-- | src/widgets/kernel/qwidget.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 81c6a6f7d83..ec7b5ce69ae 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -13235,6 +13235,24 @@ void QWidgetPrivate::setNetWmWindowTypes(bool skipIfMissing) #endif } +/*! + \internal + \return \c true, if a child with \param policy exists and isn't a child of \param excludeChildrenOf. + Return false otherwise. + */ +bool QWidgetPrivate::hasChildWithFocusPolicy(Qt::FocusPolicy policy, const QWidget *excludeChildrenOf) const +{ + Q_Q(const QWidget); + const QWidgetList &children = q->findChildren<QWidget *>(Qt::FindChildrenRecursively); + for (const auto *child : children) { + if (child->focusPolicy() == policy && child->isEnabled() + && (!excludeChildrenOf || !excludeChildrenOf->isAncestorOf(child))) { + return true; + } + } + return false; +} + #ifndef QT_NO_DEBUG_STREAM namespace { |
