Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Fastest way to select qtreeview items programatically...



  • Hey

    I sweat I was asking for it before but I cant find topic... in any case... is this the fastest way ?

                    QItemSelection sel;        
                    QVector<QItemSelection>selList(items.size());
                    for (int x = 0; x < items.size(); ++x) {
                        selList[x]= QItemSelection(items[x], items[x]);
                    }
                    for (int x = 0; x < items.size(); ++x) {
                        sel.merge(selList[x], QItemSelectionModel::Select);
                    }
                    mSelectionRangeOld = selectionModel()->selection();
                    if (cSel) {
                        selectionModel()->clearSelection();
                    }
                    if (extend) {
                        selectionModel()->select(sel, QItemSelectionModel::Select | QItemSelectionModel::Rows);
                    } else {
                        selectionModel()->select(sel, QItemSelectionModel::Deselect | QItemSelectionModel::Rows);
                    }
    

    Can any part of it be done in thread? I'm worried with 20-30k rows & 10 columns could be slow... like very slow...

    TIA


  • Lifetime Qt Champion

    Hi,

    Out of curiosity, why do you need to select that much elements programmatically ?



  • @SGaist 3D app, say user selects 50k meshes, I need to reflect that in tree view :- )



  • Never tried selecting 50K items before. But if they happen in a single method call/forloop, it'll likely be much faster if you:

    1. Stop UI updates by calling qtreeview->setUpdatesEnabled(false) at the beginning and qtreeview->setUpdatesEnabled(true)at the end.
    2. Stop item related signals from being generated by calling qtreeview->blockSignals(true) at the beginning and qtreeview->blockSignals(false) at the end.

    Once this is done, then the only cpu usage would be qtreeview model being updated and final UI update at the end.


  • Lifetime Qt Champion

    Why would someone see 50k meshes in a tree view? What should the user do with this information...


Log in to reply