aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quickcontrols2/controls/data/tst_dialogbuttonbox.qml
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2022-04-22 16:00:55 +0800
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-04-25 05:12:36 +0000
commit15b03052bc4355532e7e48c8bc685c404e8a6a90 (patch)
tree93224f85b8a73c9370de7f8896495dff8ddfaccc /tests/auto/quickcontrols2/controls/data/tst_dialogbuttonbox.qml
parentcc3a6ea2ac22383e9ddaf4ff4da32a7dc5f8aa05 (diff)
DialogButtonBox: fix buttons going outside box on size change
This was removed in c2fd8f7d00e2a47724765e289b828c36c98da29c, but seems to be necessary now. A horizontal ListView's implicitWidth is 0, so setting it to contentWidth seems reasonable regardless. For more history, see 8b78d9cea3091b0bd94d1ae0c71a000f8e7e1903. Change-Id: I8647dad32adca6482e9ff971010f6e779567a36d Fixes: QTBUG-102558 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io> (cherry picked from commit 2ae87dcece1915797de8065048817707c8f4d24f) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests/auto/quickcontrols2/controls/data/tst_dialogbuttonbox.qml')
-rw-r--r--tests/auto/quickcontrols2/controls/data/tst_dialogbuttonbox.qml84
1 files changed, 83 insertions, 1 deletions
diff --git a/tests/auto/quickcontrols2/controls/data/tst_dialogbuttonbox.qml b/tests/auto/quickcontrols2/controls/data/tst_dialogbuttonbox.qml
index 11cc1f55b2..7d4c5d9e4d 100644
--- a/tests/auto/quickcontrols2/controls/data/tst_dialogbuttonbox.qml
+++ b/tests/auto/quickcontrols2/controls/data/tst_dialogbuttonbox.qml
@@ -398,7 +398,7 @@ TestCase {
// QTBUG-72886
function test_changeCustomButtonText(data) {
- var control = createTemporaryObject(customButtonBox, testCase, {})
+ var control = createTemporaryObject(data.component, testCase, {})
verify(control)
var listView = control.contentItem
@@ -418,6 +418,88 @@ TestCase {
}
Component {
+ id: customButtonBoxInDialog
+
+ Dialog {
+ width: 300
+ visible: true
+
+ footer: DialogButtonBox {
+ objectName: "customButtonBoxInDialog"
+ alignment: Qt.AlignRight
+
+ property alias okButton: okButton
+
+ Button {
+ id: okButton
+ text: "OK"
+
+ DialogButtonBox.buttonRole: DialogButtonBox.AcceptRole
+ }
+ }
+ }
+ }
+
+ Component {
+ id: customButtonBoxTwoButtonsInDialog
+
+ Dialog {
+ width: 300
+ visible: true
+
+ footer: DialogButtonBox {
+ objectName: "customButtonBoxTwoButtonsInDialog"
+ alignment: Qt.AlignRight
+
+ property alias okButton: okButton
+
+ Button {
+ id: okButton
+ text: "OK"
+
+ DialogButtonBox.buttonRole: DialogButtonBox.AcceptRole
+ }
+ Button {
+ text: "Cancel"
+
+ DialogButtonBox.buttonRole: DialogButtonBox.RejectRole
+ }
+ }
+ }
+ }
+
+ function test_changeCustomButtonImplicitWidth_data() {
+ return [
+ { tag: "oneButton", component: customButtonBoxInDialog },
+ { tag: "twoButtons", component: customButtonBoxTwoButtonsInDialog },
+ ]
+ }
+
+ // QTBUG-102558
+ function test_changeCustomButtonImplicitWidth(data) {
+ let dialog = createTemporaryObject(data.component, testCase, {})
+ verify(dialog)
+
+ let control = dialog.footer
+ verify(control)
+
+ let listView = control.contentItem
+ waitForRendering(listView)
+
+ let button = control.okButton
+ verify(button)
+ button.implicitWidth *= 1.5
+
+ // The button should never go outside of the box.
+ tryVerify(function() { return button.mapToItem(control, 0, 0).x >= 0 },
+ 1000, "Expected left edge of button to be within left edge of DialogButtonBox (i.e. greater than or equal to 0)" +
+ ", but it's " + button.mapToItem(control, 0, 0).x)
+ tryVerify(function() { return button.mapToItem(control, 0, 0).x + button.width <= control.width },
+ 1000, "Expected right edge of button to be within right edge of DialogButtonBox (i.e. less than or equal to " +
+ control.width + "), but it's " + (button.mapToItem(control, 0, 0).x + button.width))
+ }
+
+ Component {
id: noRolesDialog
Dialog {