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. selectedRows() on TreeView with ExtendedSelection is one step behind
Forum Updated to NodeBB v4.3 + New Features

selectedRows() on TreeView with ExtendedSelection is one step behind

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 2 Posters 899 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.
  • E Offline
    E Offline
    ehsanen
    wrote on last edited by ehsanen
    #1

    Hi everyone,
    I have a treeview in the qml, the selection mode is ExtendedSelection. Whenever the selected index changes by the user I need to exactly know which tree rows are selected. Here is the TreeView:

    Controls.TreeView {
                 id: myTreeView
                 Controls.TableViewColumn {
                      title: "Name"
                      role: "name"
                 }
    
                 headerVisible: false
                 anchors.fill: parent
                 selection: ItemSelectionModel {
                    onCurrentIndexChanged: {
                      console.log(myTreeView.selection.selectedRows(0))
                      console.log(currentIndex)
                     }
                 }
    
                 selectionMode: Controls.SelectionMode.ExtendedSelection
                 onDoubleClicked: {
                  if (isExpanded(index))
                       collapse(index);
                  else
                       expand(index);
                  }
    
        }
    

    In the example above I just try to print the selected rows to the console to make sure I have the right selection. currentIndex always holds the last selected index(as expected), but the selection.selectedRows() which is supposed to hold all the rows that are currently selected, is always one step behind. For example:

    if user (while holding Ctrl) selects rows 1, 2, 3 one by one the selection.selectedRows() will be null, "1", "1,2" and currentIndex will be 1, 2, 3 respectively. Combining these two together, one can get the list of all indexes that are in selected state.
    My problem is that if the user releases the Ctrl and selects row 4, then the selection.selectedRows() will be "1,2,3" although it should be null.
    To summarize it is not possible to distinguish between the case that the user selects (holding Ctrl) rows 1,2,3,4 and the case in which user first selects rows (holding Ctrl) 1,2,3 and then releases Ctrl and just selects row 4.

    I have also tested with myTreeView.selection.selectedIndexes, but still the same behaviour.
    It looks like a bug in TreeView to me, please advice how to solve.

    Thanks.

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by p3c0
      #2

      @ehsanen
      onCurrentIndexChanged may not be the appropriate handler for this scenario. Try using onSelectionChanged:

      ItemSelectionModel {
          model: myModel
          onSelectionChanged: {
              console.log(selectedIndexes)
          }
      }
      

      157

      1 Reply Last reply
      1

      • Login

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