Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Can't add to ItemSelectionModel list of selected model indexes
Forum Updated to NodeBB v4.3 + New Features

Can't add to ItemSelectionModel list of selected model indexes

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 1 Posters 288 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ocgltdO Offline
    ocgltdO Offline
    ocgltd
    wrote on last edited by
    #1

    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)
            }
        }
    }
    
    ocgltdO 1 Reply Last reply
    0
    • ocgltdO ocgltd

      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)
              }
          }
      }
      
      ocgltdO Offline
      ocgltdO Offline
      ocgltd
      wrote on last edited by
      #2

      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).

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved