Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How can I select a child node in a QTreeView?

How can I select a child node in a QTreeView?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 2.7k Views
  • 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.
  • N Offline
    N Offline
    nzur
    wrote on last edited by VRonin
    #1

    Hi, I have a QTreeView with nested nodes, I need to select a child node according to an index in a table.
    Here's what I do:

            QModelIndex nIndex = view.model()->index(tableIndex, 0);
            view.selectionModel()->clearSelection();
            view.selectionModel()->select(nIndex, QItemSelectionModel::Select | QItemSelectionModel::Rows);
            view.scrollTo(nIndex);
    

    for example: when tableIndex == 3 I expect to select the 3rd child node, but this selects the 3rd parent row

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      The third child node of what ? Overall ? Of the top level item ? Of the third top level item ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #3

        @nzur said in How can I select a child node in a QTreeView?:

        index(tableIndex, 0)

        You are missing the 3rd argument of index. How can it know what parent to take it from? for example, for the third child of the first parent:
        QModelIndex nIndex = view.model()->index(tableIndex, 0, view.model()->index(0,0));

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        1 Reply Last reply
        2
        • N Offline
          N Offline
          nzur
          wrote on last edited by
          #4

          Thx, That's it!!!

          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