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. How to gather only displayed listViewItems to save on performance
Forum Update on Monday, May 27th 2025

How to gather only displayed listViewItems to save on performance

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 4 Posters 534 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.
  • Q Offline
    Q Offline
    Q139
    wrote on last edited by
    #1

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

    J.HilkJ 1 Reply Last reply
    0
    • Q Q139

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

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @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


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      3
      • Q Offline
        Q Offline
        Q139
        wrote on last edited by Q139
        #3

        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

        JonBJ 1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

          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)

          Q 1 Reply Last reply
          4
          • Q Q139

            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

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #5

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

            Q 1 Reply Last reply
            0
            • JonBJ JonB

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

              Q Offline
              Q Offline
              Q139
              wrote on last edited by Q139
              #6

              @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.

              JonBJ 1 Reply Last reply
              0
              • Q Q139

                @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.

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by
                #7

                @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.

                Q 1 Reply Last reply
                2
                • JonBJ JonB

                  @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.

                  Q Offline
                  Q Offline
                  Q139
                  wrote on last edited by
                  #8

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

                  1 Reply Last reply
                  1
                  • mrjjM mrjj

                    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)

                    Q Offline
                    Q Offline
                    Q139
                    wrote on last edited by Q139
                    #9
                    This post is deleted!
                    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