diff options
| author | Oliver Eftevaag <oliver.eftevaag@qt.io> | 2025-10-17 09:24:01 +0200 |
|---|---|---|
| committer | Oliver Eftevaag <oliver.eftevaag@qt.io> | 2025-11-14 08:59:57 +0100 |
| commit | 4d1753b95f0343a68f80a1b482b8ab9a0397fecb (patch) | |
| tree | dd77a4d37237f0db20d3b48fba63e750699765f4 /src/quickdialogs/quickdialogsquickimpl/qquickfiledialogimpl.cpp | |
| parent | f2e3d67e32c7cbab101f1166b4eb906ecb546fde (diff) | |
DialogButtonBox: add properties for setting a default button
Qt Quick Controls lacked the ability for setting a default button in a
dialog button box. This is something that we support in QtWidgets, and
it makes sense to allow dialogs with a DialogButtonBox set as the footer
to decide if a particular button should be default, and have focus when
the dialog is opened.
With this patch, we're introducing two different ways for selecting a
default button.
The first is the usage of the DialogButtonBox::defaultButton property,
which works like this:
```
DialogButtonBox {
defaultButton: Button {
text: qsTr("Ok")
}
Button {
text: qsTr("Cancel")
}
}
```
In the snippet above, the Button that is set as default should both be
highlighted, and be the sub focus item of the DialogButtonBox.
However, since the standardButtons property can be used to dynamically
create buttons on the fly, we also needed an alternative way for picking
a default button.
In cases where standardButtons is being used to create buttons in the
DialogButtonBox, the new defaultStandardButton property can be used:
```
DialogButtonBox {
standardButtons: DialogButtonBox.Yes | DialogButtonBox.No
defaultStandardButton: DialogButtonBox.Yes
}
```
Something worth noting, is that the DialogButtonBox's contentItem is
typically a ListView. ListView have the ItemIsFocusScope flag set,
meaning that we need to give focus to both the ListView, and the default
Button.
In addition, the FontDialog and ColorDialog will now make the Ok button
default, and give it focus when the dialogs are opened.
The FileDialog and FolderDialog will continue to give the ListView
focus, since that's IMO more user friendly. The MessageDialog will need
new API to take full advantage of this new feature, which will be
introduced later.
[ChangeLog][DialogButtonBox] The DialogButtonBox now has two new
properties, defaultButton and defaultStandardButton. When one of these
properties are being used, a button set as default will be highlighted
and receive activeFocus whenever the DialogButtonBox gets focus. If
a DialogButtonBox is assigned as a Dialog's footer, it will also get
focus when the Dialog is opened. This means that a Dialog with a
DialogButtonBox as its footer, will give focus to a default button when
opened. If both of these properties are unset, the first button with the
AcceptRole will get focus, but it will not be highlighted.
Fixes: QTBUG-58246
Fixes: QTBUG-139352
Change-Id: Ic083410184dd63e0e790694f782a7a98c1dc8b6e
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/quickdialogs/quickdialogsquickimpl/qquickfiledialogimpl.cpp')
| -rw-r--r-- | src/quickdialogs/quickdialogsquickimpl/qquickfiledialogimpl.cpp | 2 |
1 files changed, 0 insertions, 2 deletions
diff --git a/src/quickdialogs/quickdialogsquickimpl/qquickfiledialogimpl.cpp b/src/quickdialogs/quickdialogsquickimpl/qquickfiledialogimpl.cpp index 2c4171e680..ccbf2f177b 100644 --- a/src/quickdialogs/quickdialogsquickimpl/qquickfiledialogimpl.cpp +++ b/src/quickdialogs/quickdialogsquickimpl/qquickfiledialogimpl.cpp @@ -262,8 +262,6 @@ void QQuickFileDialogImplPrivate::handleClick(QQuickAbstractButton *button) attached && fileInfo.exists() && isSaveMode && !dontConfirmOverride) { QQuickDialog *confirmationDialog = attached->overwriteConfirmationDialog(); confirmationDialog->open(); - static_cast<QQuickDialogButtonBox *>(confirmationDialog->footer())->standardButton(QPlatformDialogHelper::Yes) - ->forceActiveFocus(Qt::PopupFocusReason); } else { selectFile(); } |
