Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-60684

Empty dropdown list shown on ComboBox after clear

    XMLWordPrintable

Details

    • 90a0d4023206cfeed1bec43cb11e026ff0379d3d

    Description

      Append first items to ComboBox&ListModel so that the drop down would need a scroll bar (more than 10 on the example). Then clear the list and check the ComboBox. It still opens the empty rectangle sized to max height. Expected would be that no rectangle would be shown. After that it keeps showing max height rectangle even with couple items. Attached is a sample application where the problem is easily tested.

      import QtQuick 2.7
      import QtQuick.Window 2.2
      import QtQuick.Controls 2.0
      
      Window {
          visible: true
          width: 300
          height: 300
          title: qsTr("Hello World")
      
          ComboBox {
              id: comboBox
              height: 30
              width: 100
              font.pixelSize: 20
      
              contentItem: Text {
                  text: comboBox.displayText
                  font: comboBox.font
                  color: comboBox.activeFocus ? "black" : "gray"
                  horizontalAlignment: Text.AlignLeft
                  verticalAlignment: Text.AlignVCenter
              }
      
              background: Rectangle {
                  color: comboBox.activeFocus ? "pink" : "skyblue"
              }
      
              delegate: ItemDelegate {
                  width: comboBox.width
                  contentItem: Text {
                      text: modelData
                      verticalAlignment: Text.AlignVCenter
                  }
                  highlighted: comboBox.highlightedIndex == index
              }
      
              model: ListModel {
              }
      
              onActivated: {
                  console.log("clicked: " + currentText + " currentIndex: " + currentIndex)
              }
          }
      
          Button{
              id: append
              text: "append"
              width: 80
              height: 30
              anchors.left: comboBox.right
              anchors.leftMargin: 3
      
              property int number: 0
      
              onClicked: {
                  comboBox.model.append({"modelData": number})
                  number++
      
                  console.log("count " + comboBox.count);
              }
          }
      
          Button{
              text: "clear"
              width: 80
              height: 30
              anchors.left: append.right
              anchors.leftMargin: 3
      
              property int number: 0
      
              onClicked: {
                  comboBox.model.clear()
              }
          }
      }
      

      Attachments

        1. 0.png
          0.png
          13 kB
        2. 1.png
          1.png
          17 kB
        3. 2.png
          2.png
          11 kB
        4. 3.png
          3.png
          10 kB
        5. QTBUG-60684.zip
          2 kB

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              mitch_curtis Mitch Curtis
              misalmel Mika Salmela
              Votes:
              2 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes