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

How to gather only displayed listViewItems to save on performance



  • How to gather only all displayed listViewItems to save on performance on data updates with long lists?


  • Moderators

    @Q139 what do you mean with gather ?

    Is this, QML or QWidgets ?
    Qt Version ?
    OS?
    Compiler?

    Have you seen this example?
    https://doc.qt.io/qt-5/qtwidgets-itemviews-fetchmore-example.html



  • To get indexes or pointers of QListViewItems currently displayed for example, to update the visible data and not update invisible ones.
    I have list with more than 100k items, it drains performance if user causes some changes that triggers QListViewItems data and color updating code.

    QWidgets
    Latest Qt
    Win 10
    Mingw


  • Lifetime Qt Champion

    Hi

    You can do use visualRect with indexAt to check if they are shown.

    something like

    
    QList <QModelIndex>myList;
    void ListVisible( QListView *view) {
    
        QModelIndex firstIndex = view->indexAt(QPoint(0, 0));
        if (firstIndex.isValid()) {
            myList << firstIndex;
        }
        while (view->viewport()->rect().contains(QPoint(0,
                                                        view->visualRect(firstIndex).y() + 
                                                        view->visualRect(firstIndex).height() + 1 ))) {
            firstIndex =  view->indexAt(QPoint(0,
                                               view->visualRect(firstIndex).y() + 
                                               view->visualRect(firstIndex).height() + 1 ));
            myList << firstIndex;
        }
        qDebug() << myList.count() << "are visible";
    }
    

    Do note that if one pixels is visible for the last item, its included. so partly shown is also added.

    Credits to Qt wiki. (cant find page currently)



  • @Q139
    OOI, what is the point of having a visual "list with more than 100k items"?



  • @JonB
    At first had few items and for 40 items it was fine to loop trough and update all items.
    Didnot imagine to load 100k+ items into that program.

    It displays loaded files and missing/repaired data with various background colors and numbers.

    Recently i have had thoughts of also implementing a search bar to filter but showing all and scrolling gets nice visual overview of data and it has helped with debugging alot over the years.

    listWidget performs great with large amount of data if used properly and not updating too many values/colors once.



  • @Q139
    It may perform OK for a large number of items, I just don't get what the point would be to offer the user so many items in a list.



  • @JonB
    Yes ,it's too much info for human to process, Will redesign it soon to search based list.



  • This post is deleted!

Log in to reply