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. Qt model/view framework selection system - store/restore selections
QtWS25 Last Chance

Qt model/view framework selection system - store/restore selections

Scheduled Pinned Locked Moved Solved General and Desktop
qitemselectionqabstractitemmo
2 Posts 1 Posters 519 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 last edited by Dariusz
    #1

    Hey

    I'm trying to wrap my head around selections in qt. I'd like to store my selection & perform some action(like renaming selected items) and then restore it.

    I know I can get selectedIndexes(), but how can I get QItemSelection/QItemSelectionRange object instead? Or how can I convert my selectedIndexes() to QItemSelection/Range ?

    I have 20k items and selecting them/reselecting takes quite a bit of time.

    Say if I try to re-select items from selectedIndexes()

    auto selectedItems = selectedIndexes();
    for(auto&itm:selectedItems ){
         do stuff
         selectionModel()->select(itm, QItemSelectionModel::Select | QItemSelectionModel::Rows);
         }
    

    This can take minutes... from debug that function is marked as 90% time

    I also tried using this:

    ...
    QItemSelection sel = selectionModel()->selection();
    for(auto&itm:selectedIndexes()){
         do stuff
         }
    selectionModel()->select(sel,QItemSelectionModel::Select | QItemSelectionModel::Rows);
    ...
    

    But this did not do anything. It does not re-select the items.
    I run my selection function after QTreeView::mouseReleaseEvent(event);
    Where am I hitting the wall here?

    D 1 Reply Last reply
    0
    • D Dariusz

      Hey

      I'm trying to wrap my head around selections in qt. I'd like to store my selection & perform some action(like renaming selected items) and then restore it.

      I know I can get selectedIndexes(), but how can I get QItemSelection/QItemSelectionRange object instead? Or how can I convert my selectedIndexes() to QItemSelection/Range ?

      I have 20k items and selecting them/reselecting takes quite a bit of time.

      Say if I try to re-select items from selectedIndexes()

      auto selectedItems = selectedIndexes();
      for(auto&itm:selectedItems ){
           do stuff
           selectionModel()->select(itm, QItemSelectionModel::Select | QItemSelectionModel::Rows);
           }
      

      This can take minutes... from debug that function is marked as 90% time

      I also tried using this:

      ...
      QItemSelection sel = selectionModel()->selection();
      for(auto&itm:selectedIndexes()){
           do stuff
           }
      selectionModel()->select(sel,QItemSelectionModel::Select | QItemSelectionModel::Rows);
      ...
      

      But this did not do anything. It does not re-select the items.
      I run my selection function after QTreeView::mouseReleaseEvent(event);
      Where am I hitting the wall here?

      D Offline
      D Offline
      Dariusz
      wrote on last edited by
      #2

      @Dariusz I'm a nob. I captured selection range after action and not before. Storing selection before calling QTreeView::mouseReleaseEvent(event); seems to have solved the issue.

      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