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. [SOLVED] Find out which items are selected in QTreeView when using ExtendedSelection?

[SOLVED] Find out which items are selected in QTreeView when using ExtendedSelection?

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 2.2k 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.
  • A Offline
    A Offline
    Adelost
    wrote on last edited by
    #1

    I have a QTreeView where I can select multiple rows by holding down "Ctrl".

    To do this, I have used:
    @setSelectionMode(QAbstractItemView::ExtendedSelection);@

    To find out which item is clicked I used to look at the signal
    @clicked( const QModelIndex &)@

    However, now that I can have multiple items selected, how can I find out which items are selected, and ignore the ones that are not?

    1 Reply Last reply
    0
    • R Offline
      R Offline
      Rondog
      wrote on last edited by
      #2

      Something like this should work:

      @
      QModelIndexList index_list = abstract_view->selectedIndexes();
      @

      QModelIndexList is simply QList<QModelIndex> so you can use standard iterators to run the list of items.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Mario84
        wrote on last edited by
        #3

        You should also have a look at QAbstractItemView::selectionModel() and the QItemSelectionModel class returned by this method.
        It gives you more detailed information and possibilities to modifiy the selection...

        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