Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How in ComboBox to make a dropdown list by the width of the text



  • Hi!
    How in ComboBox to make a dropdown list by the width of the text?



  • @Mihaill
    What does this mean? I believe that by default Qt combo boxes automatically size the dropdown to accommodate the widest text in the choices, is that what you mean, is that not the case?



  • Yeah, that's what I meant.



  • Did so, but now does not change currentindex

                delegate: ItemDelegate {
                    width: comboBoxProfilOptions.width
                    height: 25
                    highlighted: comboBoxProfilOptions.highlightedIndex === index
                    hoverEnabled: comboBoxProfilOptions.hoverEnabled
                    Rectangle{
                        anchors.fill: parent
                        border.width: 1
                        border.color: "black"
                        color: "#00000000"
                    }
                    
                    Label{
                        x: 3
                        anchors.verticalCenter: parent.verticalCenter
                        width: parent.width
                        text: text1
                        font.pixelSize: comboBoxProfilOptions.font.pixelSize
                        //color: "red"
                    }
                }
    


  • Hi @Mihaill , can you explain a bit better?Are you telling you are not able to change the currentIndex in the comboBox or are you telling that you are able to customize the current selected item i.e,
    ebfae5c7-75d4-4161-8c64-39920cf518d0-image.png



  • With this delegate, I can either display delegates without text but select the text I want, or display text in delegates but not select the text I want. You don't know the delegate samples for ComboBox?


Log in to reply