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 Updated to NodeBB v4.3 + New Features

Capture item selection via mouse of treeview?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 341 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.
  • S Offline
    S Offline
    SRaD
    wrote on 2 Jun 2019, 00:41 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
    • C Offline
      C Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on 2 Jun 2019, 07:37 last edited by Chris Kawa 6 Feb 2019, 07:38
      #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

      1/2

      2 Jun 2019, 00:41

      • Login

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