From 90a0d4023206cfeed1bec43cb11e026ff0379d3d Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Wed, 31 May 2017 17:14:49 +0200 Subject: 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 --- src/imports/controls/universal/ComboBox.qml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/imports/controls/universal') diff --git a/src/imports/controls/universal/ComboBox.qml b/src/imports/controls/universal/ComboBox.qml index 5a6ced60..a2ba0236 100644 --- a/src/imports/controls/universal/ComboBox.qml +++ b/src/imports/controls/universal/ComboBox.qml @@ -35,6 +35,7 @@ ****************************************************************************/ import QtQuick 2.9 +import QtQuick.Window 2.3 import QtQuick.Controls 2.2 import QtQuick.Templates 2.2 as T import QtQuick.Controls.Universal 2.2 @@ -132,7 +133,7 @@ T.ComboBox { popup: T.Popup { width: control.width - implicitHeight: Math.min(396, contentItem.implicitHeight) + height: Math.min(contentItem.implicitHeight, control.Window.height - topMargin - bottomMargin) topMargin: 8 bottomMargin: 8 -- cgit v1.2.3