summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@qt.io>2017-11-08 14:56:29 +0100
committerJ-P Nurmi <jpnurmi@qt.io>2018-02-22 14:59:37 +0000
commitf1f884d353c5a9190e200cc04e94d4658c69a23b (patch)
tree23d3d44ab447842dca6b9c22b6bf12c887ccd151
parente80d273e6f19ba0a6a0f4e830724a36785ef19f6 (diff)
DialogButtonBox: workaround implicit size calculation with one buttonv5.11.0-beta1
When there's only one button in the dialog button box, the Default and Universal styles resize the button to cover half of the button box. This works in typical scenarios when the dialog button box is assigned as a footer of a dialog, and thus, gets resized together with the dialog. However, if the dialog button box is placed into a layout, or otherwise not given an explicit size, the implicit size calculation loops until it reaches zero. 1) button box gets the implicit size of the content (one button) 2) button box resizes the button to cover half of the box width 3) button box re-calculates its implicit size => step 1 Avoid the problem by providing a reasonable hard-coded implicit size for this special case. Notice that this is just a temporary workaround to avoid the problem. This can be fixed properly in dev by providing separate contentWidth and contentHeight properties that cleanly propagate the content size to QML. Task-number: QTBUG-59719 Change-Id: I552e0824ae6bff26b570c699252a3e4f09bd3397 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
-rw-r--r--src/imports/controls/DialogButtonBox.qml2
-rw-r--r--src/imports/controls/imagine/DialogButtonBox.qml2
-rw-r--r--src/imports/controls/universal/DialogButtonBox.qml2
-rw-r--r--src/quicktemplates2/qquickdialogbuttonbox.cpp4
-rw-r--r--tests/auto/controls/data/tst_dialogbuttonbox.qml28
5 files changed, 33 insertions, 5 deletions
diff --git a/src/imports/controls/DialogButtonBox.qml b/src/imports/controls/DialogButtonBox.qml
index 51a5cc49..3189967d 100644
--- a/src/imports/controls/DialogButtonBox.qml
+++ b/src/imports/controls/DialogButtonBox.qml
@@ -54,7 +54,7 @@ T.DialogButtonBox {
}
contentItem: ListView {
- implicitWidth: contentWidth
+ implicitWidth: control.count === 1 ? 200 : contentWidth
implicitHeight: 40
model: control.contentModel
diff --git a/src/imports/controls/imagine/DialogButtonBox.qml b/src/imports/controls/imagine/DialogButtonBox.qml
index d24ad4ee..69211ed9 100644
--- a/src/imports/controls/imagine/DialogButtonBox.qml
+++ b/src/imports/controls/imagine/DialogButtonBox.qml
@@ -60,7 +60,7 @@ T.DialogButtonBox {
}
contentItem: ListView {
- implicitWidth: contentWidth
+ implicitWidth: control.count === 1 ? 200 : contentWidth
implicitHeight: 32
model: control.contentModel
diff --git a/src/imports/controls/universal/DialogButtonBox.qml b/src/imports/controls/universal/DialogButtonBox.qml
index 7f28a144..17a9156d 100644
--- a/src/imports/controls/universal/DialogButtonBox.qml
+++ b/src/imports/controls/universal/DialogButtonBox.qml
@@ -58,7 +58,7 @@ T.DialogButtonBox {
}
contentItem: ListView {
- implicitWidth: contentWidth
+ implicitWidth: control.count === 1 ? 200 : contentWidth
implicitHeight: 32
model: control.contentModel
diff --git a/src/quicktemplates2/qquickdialogbuttonbox.cpp b/src/quicktemplates2/qquickdialogbuttonbox.cpp
index cd971139..f16f1b74 100644
--- a/src/quicktemplates2/qquickdialogbuttonbox.cpp
+++ b/src/quicktemplates2/qquickdialogbuttonbox.cpp
@@ -215,8 +215,8 @@ void QQuickDialogButtonBoxPrivate::resizeContent()
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->implicitWidth();
- qreal ch = (alignment & Qt::AlignVertical_Mask) == 0 ? q->availableHeight() : contentItem->implicitHeight();
+ 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);
}
diff --git a/tests/auto/controls/data/tst_dialogbuttonbox.qml b/tests/auto/controls/data/tst_dialogbuttonbox.qml
index 044c9593..6faf0db4 100644
--- a/tests/auto/controls/data/tst_dialogbuttonbox.qml
+++ b/tests/auto/controls/data/tst_dialogbuttonbox.qml
@@ -195,4 +195,32 @@ TestCase {
compare(clickedSpy.signalArguments[0][0], button)
compare(roleSpy.count, 1)
}
+
+ function test_implicitSize_data() {
+ return [
+ { tag: "Ok", standardButtons: DialogButtonBox.Ok },
+ { tag: "Yes|No", standardButtons: DialogButtonBox.Yes | DialogButtonBox.No }
+ ]
+ }
+
+ // QTBUG-59719
+ function test_implicitSize(data) {
+ var control = createTemporaryObject(buttonBox, testCase, {standardButtons: data.standardButtons})
+ verify(control)
+
+ var listView = control.contentItem
+ verify(listView && listView.hasOwnProperty("contentWidth"))
+ waitForRendering(listView)
+
+ var implicitContentWidth = control.leftPadding + control.rightPadding
+ for (var i = 0; i < listView.contentItem.children.length; ++i) {
+ var button = listView.contentItem.children[i]
+ if (!button.hasOwnProperty("text"))
+ continue
+ implicitContentWidth += button.implicitWidth
+ }
+
+ verify(implicitContentWidth > control.leftPadding + control.rightPadding)
+ verify(control.implicitWidth >= implicitContentWidth, qsTr("implicit width (%1) is less than content width (%2)").arg(control.implicitWidth).arg(implicitContentWidth))
+ }
}