aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/controls/data/tst_dialogbuttonbox.qml
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2018-12-10 14:04:53 +0100
committerMitch Curtis <mitch.curtis@qt.io>2019-01-08 15:10:54 +0000
commit6476de0b669162cf08c11f5c8d5ad0b42419f365 (patch)
tree8963f12221b3eaf25fa5bd9f8d1c76f5f96e46c2 /tests/auto/controls/data/tst_dialogbuttonbox.qml
parent0ca69961a2bd544cd417d849018427ae0c8cda05 (diff)
DialogButtonBox: fix issue where single button would go outside box
c2fd8f7d made the following changes to the geometry calculation of QQuickDialogButtonBox's contentItem: @@ -244,11 +252,8 @@ void QQuickDialogButtonBoxPrivate::resizeContent() return; QRectF geometry = q->boundingRect().adjusted(q->leftPadding(), q->topPadding(), -q->rightPadding(), -q->bottomPadding()); - if (alignment != 0) { - qreal cw = (alignment & Qt::AlignHorizontal_Mask) == 0 ? q->availableWidth() : contentItem->property("contentWidth").toReal(); - qreal ch = (alignment & Qt::AlignVertical_Mask) == 0 ? q->availableHeight() : contentItem->property("contentHeight").toReal(); - geometry = alignedRect(q->isMirrored() ? Qt::RightToLeft : Qt::LeftToRight, alignment, QSizeF(cw, ch), geometry); - } + if (alignment != 0) + geometry = alignedRect(q->isMirrored() ? Qt::RightToLeft : Qt::LeftToRight, alignment, QSizeF(contentWidth, contentHeight), geometry); It turns out that this breaks the use case of a fixed width box (e.g. where a Dialog is assigned a width of 400 and the box assumes that width) with a single button. For example, in the case of the Default style, QQuickDialogButtonBox::contentWidth is 100 because Button's implicitWidth is 100. Since contentWidth is "used for calculating the total implicit width" of the box, it's not useful for positioning items which have an explicit width. The result is that QQuickDialogButtonBox thinks the contentItem is smaller than it really is, and therefore the ListView is positioned too far to the right. Only the Default and Universal styles are affected, as they are the only styles that resize the button to cover half of the button box. This patch fixes the issue by reverting the code above to its original state, where the content size of the contentItem is used instead of the contentWidth of the box. Change-Id: Idd2f94f3b4d3413fc2057c0ade2efdd66d701c08 Fixes: QTBUG-72372 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'tests/auto/controls/data/tst_dialogbuttonbox.qml')
-rw-r--r--tests/auto/controls/data/tst_dialogbuttonbox.qml17
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/auto/controls/data/tst_dialogbuttonbox.qml b/tests/auto/controls/data/tst_dialogbuttonbox.qml
index 43153c94..62789a47 100644
--- a/tests/auto/controls/data/tst_dialogbuttonbox.qml
+++ b/tests/auto/controls/data/tst_dialogbuttonbox.qml
@@ -275,4 +275,21 @@ TestCase {
compare(okButton.width + cancelButton.width, control.availableWidth - control.spacing)
}
+
+ function test_oneButtonInFixedWidthBox() {
+ var control = createTemporaryObject(buttonBox, testCase,
+ { width: 400, standardButtons: Dialog.Close })
+ verify(control)
+
+ var listView = control.contentItem
+ waitForRendering(listView)
+
+ var button = control.itemAt(0)
+ verify(button)
+
+ // The button should never go outside of the box.
+ var buttonPosInBox = button.mapToItem(control, 0, 0)
+ verify(buttonPosInBox.x >= 0)
+ verify(buttonPosInBox.x + button.width < control.width)
+ }
}