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. Fastest way to select lots of items in QTreeView programatically?

Fastest way to select lots of items in QTreeView programatically?

Scheduled Pinned Locked Moved Unsolved General and Desktop
qitemselection
4 Posts 3 Posters 825 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.
  • D Offline
    D Offline
    Dariusz
    wrote on 30 Dec 2018, 22:52 last edited by
    #1

    Hey

    I have few thousand of items to select in my treeView and something tells me that this code:

        for (int x = 0; x < nodeList.size(); ++x) {
            selectionModel()->select(nodeList[x]->index(), QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
        }
    

    will not be very fast. How can I do this action quicker? Should I create a QItemSelection there per each item and then bundle them all up under 1 larger selection range(via QItemSelection.merge?) and select that? The items may/may not be next to each other.

    Something like :

        QItemSelection sel;
        for (int x = 0; x < nodeList.size(); ++x) {
            QModelIndex inx = nodeList[x]->index();
            sel.merge(QItemSelection(inx, inx), QItemSelectionModel::Select | QItemSelectionModel::Rows);
        }
        selectionModel()->select(sel, QItemSelectionModel::Select | QItemSelectionModel::Rows);
    
    

    TIA

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 30 Dec 2018, 23:00 last edited by
      #2

      Hi,

      Are these items all random ?

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

      D 1 Reply Last reply 30 Dec 2018, 23:04
      0
      • S SGaist
        30 Dec 2018, 23:00

        Hi,

        Are these items all random ?

        D Offline
        D Offline
        Dariusz
        wrote on 30 Dec 2018, 23:04 last edited by Dariusz
        #3

        @SGaist Yup

        I could maybe group all ModelIndexes in 1 vector, then sort them, then try and produce a "groups of indexes" that are next to each other so that I make lesss QItemSelections/merge actions?

        1 Reply Last reply
        0
        • C Offline
          C Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on 30 Dec 2018, 23:13 last edited by Chris Kawa
          #4

          I found out the hard way that for large selections using the QItemSelectionModel::Rows option is a massive performance killer. The algorithm for extending the selection doesn't seem to be very good.
          I had a case where manually creating QItemSelection with items for all columns and then selecting it in one call without that flag gave me even 30x boost. Give it a try.

          1 Reply Last reply
          3

          1/4

          30 Dec 2018, 22:52

          • Login

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