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. Deselect an index from TreeView in QML
Forum Updated to NodeBB v4.3 + New Features

Deselect an index from TreeView in QML

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 933 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,
    I would like to deselect an index in a Treeview programmatically and from QML. I have a function that accepts the QModelIndex of the tree node that needs to be deselected and I do the following:

    function deselectNode(index)
    {
     myTreeView.selection.select(index, ItemSelectionModel.Deselect)
    }
    

    I expect this function to trigger the selectionChanged event on the tree and deselect that index, but it does nothing. I also tried with Toggle. Is there another way to deselect just one single node from tree?
    In other words, I want to do what Cmd/Ctrl + Click on a tree node does, but in Qml.

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

      @ehsanen Did you set ItemSelectionModel for TreeView ?

      selection: ItemSelectionModel {
          model: myModel
      }
      

      However it didnt work with the SingleSelection (possibly a bug?) but it does if you set other mode for eg. ExtendedSelection

      selectionMode: SelectionMode.ExtendedSelection
      

      157

      1 Reply Last reply
      0
      • E Offline
        E Offline
        ehsanen
        wrote on last edited by
        #3

        Sorry my mistake. The code I provided actually works, the problem was I was selecting another node of the tree mistakenly in another part of my code.

        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