Qt World Summit: Submit your Presentation

Can't add to ItemSelectionModel list of selected model indexes

  • I have a simple QQC2 TreeView and when I click an item in my tree I want to add it to my ItemSelectionModel. Based on docs and examples online I have created the code below. And when clicking an item in my tree it correctly highlights as current, and the onCurrentModelIndexChanged handler fires.

    When the handler fires the hasSelection shows true, and the current model index printed is correct. However, the selectedIndex list is always empty. Why is the list not being populated?

    Rectangle {
        id: paneMenu
        anchors.fill: parent
        color: gui.colorRGBString(GUIConstants.EColorElement_Background)
        TreeView {
            id: mytreeview
            anchors.fill: parent
            model: treemodel
            delegate: delegateMenuItem
            onCurrentModelIndexChanged: {
                selModel.select(currentModelIndex, ItemSelectionModel.Select | ItemSelectionModel.Current)
                console.log("**selModel has selection: "+selModel.hasSelection)
                console.log("**Selected indexes:"+selModel.selectedIndexes)
                console.log("**Current model index:"+currentModelIndex)

  • It's starting to look like a bug...but this is so simple I can't understand how it got past QA. Not sure if this stems from QAbstractItemModel, SelectItemModel, or TreeView (v2).

Log in to reply