aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/controls
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2017-05-31 17:14:49 +0200
committerJ-P Nurmi <jpnurmi@qt.io>2017-05-31 19:57:09 +0000
commit90a0d4023206cfeed1bec43cb11e026ff0379d3d (patch)
treec567f103fedacfd069b7dd55c9dfeadfca26f570 /tests/auto/controls
parent830ab8aa4fa805c011eb082dfd2075ab4f03f919 (diff)
ComboBox: fix empty popup being shown after model is cleared
Currently, ComboBox's popup is sized vertically in this way: implicitHeight: contentItem.implicitHeight Adding an item to a ComboBox with an empty model and then opening the popup results in the implicitHeight being used in the line below (in QQuickPopupPositioner::reposition()): QRectF rect(p->allowHorizontalMove ? p->x : popupItem->x(), p->allowVerticalMove ? p->y : popupItem->y(), !p->hasWidth && iw > 0 ? iw : w, !p->hasHeight && ih > 0 ? ih : h); An explicit height was never set on the popup, and ih (the implicitHeight of the popupItem) is greater than 0. This is fine. However, when a ComboBox's popup item grows large enough that it has to be resized to fit within the window, its explicit height is set. The problem occurs when the model is then cleared, as the implicit height of the popup item becomes 0. So, while "!p->hasHeight" is still true, "ih > 0" is not, and the explicit height of the popup item is used, which is still the previous "let's fill the entire height of the window" size. To fix this, we bind the height of the popup to a different expression: height: Math.min(contentItem.implicitHeight, control.Window.height - topMargin - bottomMargin) This ensures that the popup has a zero height when the ListView's implicitHeight is zero (i.e the model is empty), and a height that fits within the window in all other cases. Ideally, we'd have a maximumHeight property that controls this, but for 5.9, we have to fix it this way. Task-number: QTBUG-60684 Change-Id: Ied94c79bb7b0e693be34e9c7282d991f6f704770 Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
Diffstat (limited to 'tests/auto/controls')
-rw-r--r--tests/auto/controls/data/tst_combobox.qml23
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/auto/controls/data/tst_combobox.qml b/tests/auto/controls/data/tst_combobox.qml
index 3d8777b3..95da47d7 100644
--- a/tests/auto/controls/data/tst_combobox.qml
+++ b/tests/auto/controls/data/tst_combobox.qml
@@ -1428,4 +1428,27 @@ TestCase {
compare(control.currentIndex, 0)
compare(control.currentText, "A")
}
+
+ function test_emptyPopupAfterModelCleared() {
+ var control = createTemporaryObject(comboBox, testCase, { model: 1 })
+ verify(control)
+ compare(control.popup.implicitHeight, 0)
+ compare(control.popup.height, 0)
+
+ // Ensure that it's open so that the popup's implicitHeight changes when we increase the model count.
+ control.popup.open()
+ tryCompare(control.popup, "visible", true)
+
+ // Add lots of items to the model. The popup should take up the entire height of the window.
+ control.model = 100
+ compare(control.popup.height, control.Window.height - control.popup.topMargin - control.popup.bottomMargin)
+
+ control.popup.close()
+
+ // Clearing the model should result in a zero height.
+ control.model = 0
+ control.popup.open()
+ tryCompare(control.popup, "visible", true)
+ compare(control.popup.height, 0)
+ }
}