1
votes

The combobox seems to have a problem with certain characters, at least i've detected that when we go to the item list the "&" appears as "_". How can we solve this?

An example:

ComboBox {
    id: combobox
    textRole: "text"
    Layout.fillWidth: true

    model: ListModel {
        dynamicRoles: true
    }

    Component.onCompleted: {
        reload()
    }

    Connections {
        target: trans // this is a translator from a git project you are referring to
        onLanguageChanged: {
            combobox.reload()
        }
    }

    function reload() {
        var i = combobox.currentIndex
        combobox.model = [
                    {text: qsTr("apple & orange")}
                ]
        combobox.currentIndex = i
    }

enter image description here

this is on QT 5.11.2

If i escape the text {text: qsTr("apple && orange")}

this happens

enter image description here

1

1 Answers

3
votes

Qt uses the & symbol to specify a mnemonic key for a particular UI element, so the symbol is consumed.

Simply use && instead.

As for the display text bug, there is an easy way to resolve that:

  ComboBox {
    model: ["a and b", " a && b"]
    displayText: currentText.replace("&&", "&")
  }