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. Capture item selection via mouse of treeview?
Forum Update on Monday, May 27th 2025

Capture item selection via mouse of treeview?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 340 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.
  • S Offline
    S Offline
    SRaD
    wrote on last edited by
    #1

    I am using a QTreeView where I set a custom model which is derived from QAbstractItemModel and I fill the tree with several plain classes for the tree items.

    I am trying to capture the selection by mouse of a tree item within my TreeView.

    I saw QAbstractItemView class has a clicked signal. Should I derive my plain class items from QAbstractItemView in order to capture a tree item selection or is there another way I should do this?

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by Chris Kawa
      #2

      Should I derive my plain class items from QAbstractItemView

      No, it's a view class, not an item class. QTreeView is a subclass of it. Selection is a function of a view. Selection is handled by a selection model set on a view. You should not tie selection to your model items.

      If you want to change the items in some way in response to selection change you can get the selection model from your tree view with selectionModel() and connect to its selectionChanged() signal. In the slot connected to it you can call a function on the model that will do something with the selected items, e.g. setData() with a custom role.

      1 Reply Last reply
      2

      • Login

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