Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Fastest way to select lots of items in QTreeView programatically?

    General and Desktop
    qitemselection
    3
    4
    298
    Loading More Posts
    • 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
      Dariusz last edited by

      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 Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        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 Reply Quote 0
        • D
          Dariusz @SGaist last edited by Dariusz

          @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 Reply Quote 0
          • Chris Kawa
            Chris Kawa Moderators last edited by Chris Kawa

            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 Reply Quote 3
            • First post
              Last post