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

ComboBox: change text in dropdown



  • The displayText property allows to change the visualization of the current item. For example:

    ComboBox {
        model: myModel
        displayText: currentText.replace('*','');
    }
    

    Now if the item contains a '*' it will be removed. But this happens only when the combo box is closed. I want to do the same also when the dropdown is open. How to do this?



  • @Mark81 hi,
    One way to do that is writing your own delegate for the ComboBox

    ComboBox {
            model: ["ds*f","f","ff*f"]
            displayText: currentText.replace('*','');
            delegate:
                Text{
                    text : modelData.replace('*','');
                }
        }
    

    or just clean your model before passing it to your ComboBox



  • Got it. I'm going to follow the second (and more obvious solution) because otherwise I need to rewrite the handling for colors, highlights, etc... I thought there was a way to override just the items' text.


Log in to reply