We have moved to a new Sailfish OS Forum. Please start new discussions there.

Revision history [back]

click to hide/show revision 1
initial version

posted 2016-07-14 18:44:23 +0200

QML ComboBox not updating text on load

This does not update the combobox text when the page is loaded. As soon as the box is highlighted, it shows that it is indeed assigned to the correct index, it just hasn't updated.

ComboBox {
        id : combo_type
        width: parent.width
        label: "Action Type"

        menu: ContextMenu {
            MenuItem { text: mode_mar }
            MenuItem { text: mode_script }
        }

        onEntered: {
            combo_type.currentIndex = (type === mode_mar ? 0: 1)
            update()
        }

        onCurrentIndexChanged: {
            type = combo_type.currentItem.text
        }
 }

Now I tried every event hook to get it to work, but nothing. However what did work (kinda) was bizarrely setting (true/false) enabled property

ComboBox {
        id : combo_type
        width: parent.width
        label: "Action Type"

        menu: ContextMenu {
            MenuItem { text: constant.mode_mar }
            MenuItem { text: constant.mode_script }
        }

        enabled:  {
            combo_type.currentIndex = (type === mode_mar ? 0: 1)
        }
        onCurrentIndexChanged: {
            type = combo_type.currentItem.text
        }
    }

What is going on, and what is the correct way to get my combobox to update its currentText upon page load?

QML ComboBox not updating text on load

This does not update the combobox text when the page is loaded. As soon as the box is highlighted, it shows that it is indeed assigned to the correct index, it just hasn't updated.

ComboBox {
        id : combo_type
        width: parent.width
        label: "Action Type"

        menu: ContextMenu {
            MenuItem { text: mode_mar }
            MenuItem { text: mode_script }
        }

        onEntered: {
            combo_type.currentIndex = (type === mode_mar ? 0: 1)
            update()
        }

        onCurrentIndexChanged: {
            type = combo_type.currentItem.text
        }
 }

Now I tried every event hook to get it to work, but nothing. However what did work (kinda) was bizarrely setting (true/false) enabled property

ComboBox {
        id : combo_type
        width: parent.width
        label: "Action Type"

        menu: ContextMenu {
            MenuItem { text: constant.mode_mar }
            MenuItem { text: constant.mode_script }
        }

        enabled:  {
            combo_type.currentIndex = (type === mode_mar ? 0: 1)
        }
        onCurrentIndexChanged: {
            type = combo_type.currentItem.text
        }
    }

What is going on, and what is the correct way to get my combobox to update its currentText upon page load?