From f1f884d353c5a9190e200cc04e94d4658c69a23b Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Wed, 8 Nov 2017 14:56:29 +0100 Subject: DialogButtonBox: workaround implicit size calculation with one button 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 --- tests/auto/controls/data/tst_dialogbuttonbox.qml | 28 ++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'tests/auto/controls/data') 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)) + } } -- cgit v1.2.3