Ask / Submit
0

QML ComboBox not updating text on load

asked 2016-07-14 18:44:23 +0300

tetris11 gravatar image

updated 2018-12-03 20:54:55 +0300

Tanghus gravatar image

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?

edit retag flag offensive close delete

1 Answer

Sort by » oldest newest most voted
1

answered 2016-07-15 22:06:44 +0300

coderus gravatar image
Component.onCompleted: {
    currentIndex = type === mode_mar ? 0: 1
}
edit flag offensive delete publish link more

Comments

Thanks. I'd seen this before somewhere, but didn't understand it, now I understand the need for it.

My workaround involved doing visible: { //some initialization//;return true}

tetris11 ( 2016-07-15 22:51:25 +0300 )edit
Login/Signup to Answer

Question tools

Follow
1 follower

Stats

Asked: 2016-07-14 18:44:23 +0300

Seen: 473 times

Last updated: Jul 15 '16