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 can I improving performance when I use QListView with large numbers of items
Forum Updated to NodeBB v4.3 + New Features

How can I improving performance when I use QListView with large numbers of items

Scheduled Pinned Locked Moved Solved General and Desktop
17 Posts 4 Posters 4.1k Views 2 Watching
  • 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.
  • MihanM Mihan

    Could somebody tell me the concrete method about that? I have used QListView with QAbstractTableModel to insert date.But it will makes the main UI stop a few seconds.

    It is possible to give the view hints about the data it is handling in order to improve its performance when displaying large numbers of items.

    J.HilkJ Online
    J.HilkJ Online
    J.Hilk
    Moderators
    wrote on last edited by J.Hilk
    #3

    hi @Mihan

    I had the case where I had a very fancy delegate for my ListView, that slowed things down dramatically when one would scroll very quickly.

    If that's the bottleneck for you as well, then you could do the same as me.

    Replace the delegate with a Loader, set it to asynchronous = true, and only active, if its on screen or the next/previous one in line.

    An other fancy Idea I had for that, would be to replace the ListView with a PathView (it circles around) and simply change the data accordingly. Needs a separated index management but should speed things up quickly.


    Reading through @sierdzio 's list. Seems like I reinvented the wheel as the batched layout mode is basically that ...


    And I'm talking about QML here.
    Oh man, I'm not on game today. Need more coffee!


    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.

    MihanM 2 Replies Last reply
    0
    • sierdzioS sierdzio

      A List view but Table model? That sounds weird.

      Anyway, here are some hints:

      • use lazy loading (canFetchMore() and fetchMore())
      • set uniformRowHeights or uniformItemSizes to true
      • use batched layout mode https://doc.qt.io/qt-5/qlistview.html#layoutMode-prop
      • analyze your model's data() method, make sure it runs as fast as possible
      • start loading your data even before the view is shown (on application startup, for example) - if possible
      • make sure your delegates are as simple as possible
      MihanM Offline
      MihanM Offline
      Mihan
      wrote on last edited by
      #4

      @sierdzio Wow,it's very useful that I set layoutmode to batched.Thank you so much!

      By the way,Should I change the model type?Which type of model should I use on ListView?

      1 Reply Last reply
      0
      • sierdzioS Offline
        sierdzioS Offline
        sierdzio
        Moderators
        wrote on last edited by
        #5

        There is QAbstractListModel. You don't have to change, though. If table model works for you, it can stay.

        (Z(:^

        MihanM 1 Reply Last reply
        1
        • J.HilkJ J.Hilk

          hi @Mihan

          I had the case where I had a very fancy delegate for my ListView, that slowed things down dramatically when one would scroll very quickly.

          If that's the bottleneck for you as well, then you could do the same as me.

          Replace the delegate with a Loader, set it to asynchronous = true, and only active, if its on screen or the next/previous one in line.

          An other fancy Idea I had for that, would be to replace the ListView with a PathView (it circles around) and simply change the data accordingly. Needs a separated index management but should speed things up quickly.


          Reading through @sierdzio 's list. Seems like I reinvented the wheel as the batched layout mode is basically that ...


          And I'm talking about QML here.
          Oh man, I'm not on game today. Need more coffee!

          MihanM Offline
          MihanM Offline
          Mihan
          wrote on last edited by
          #6

          @J.Hilk Oh,thank you. It may be used when I add an animation of scrolling the list~

          1 Reply Last reply
          0
          • sierdzioS sierdzio

            There is QAbstractListModel. You don't have to change, though. If table model works for you, it can stay.

            MihanM Offline
            MihanM Offline
            Mihan
            wrote on last edited by
            #7

            @sierdzio Yep,it works. I think it's just one more overloaded function (columnCount) than QAbstractListModel, rigth?
            By the way,How can i optimize the date() method. ```
            QVariant CLogSqlModel::data(const QModelIndex &index, int role) const
            {
            if(!index.isValid())
            return QVariant();
            if(role == Qt::DisplayRole)
            {
            return m_LogList.at(index.row()).LogTime.toString("yyyy.MM.dd hh:mm") + m_LogList.at(index.row()).LogDesp;
            }
            else if (role == Qt::BackgroundRole)
            {
            if(index.row()%2 == 0)
            return QColor(Qt::darkGray);
            else
            return QVariant();
            }
            else
            return QVariant();
            }

            1 Reply Last reply
            0
            • sierdzioS Offline
              sierdzioS Offline
              sierdzio
              Moderators
              wrote on last edited by
              #8

              Hm ok that looks simple enough. Only small optimization I'd suggest is for DisplayRole:

              const auto &item = m_LogList.at(index.row());
              return item.LogTime.toString("yyyy.MM.dd hh:mm") + item.LogDesp;
              

              to avoid traversing the list twice. But I don't know any implementation details here, so it is mostly a guess.

              Does m_LogList perform any heavy calculations, or complex data reads (SQL or something), or is it just a static list?

              (Z(:^

              MihanM 1 Reply Last reply
              1
              • J.HilkJ J.Hilk

                hi @Mihan

                I had the case where I had a very fancy delegate for my ListView, that slowed things down dramatically when one would scroll very quickly.

                If that's the bottleneck for you as well, then you could do the same as me.

                Replace the delegate with a Loader, set it to asynchronous = true, and only active, if its on screen or the next/previous one in line.

                An other fancy Idea I had for that, would be to replace the ListView with a PathView (it circles around) and simply change the data accordingly. Needs a separated index management but should speed things up quickly.


                Reading through @sierdzio 's list. Seems like I reinvented the wheel as the batched layout mode is basically that ...


                And I'm talking about QML here.
                Oh man, I'm not on game today. Need more coffee!

                MihanM Offline
                MihanM Offline
                Mihan
                wrote on last edited by
                #9

                @J.Hilk Oh wait,I also have a question about QML!
                Can I Use QML and UI at the sane time?
                Uh....like that I want to replace the SpinBox with Spinner ,the Spinner is on the example-Threading.

                J.HilkJ 1 Reply Last reply
                0
                • MihanM Mihan

                  @J.Hilk Oh wait,I also have a question about QML!
                  Can I Use QML and UI at the sane time?
                  Uh....like that I want to replace the SpinBox with Spinner ,the Spinner is on the example-Threading.

                  J.HilkJ Online
                  J.HilkJ Online
                  J.Hilk
                  Moderators
                  wrote on last edited by
                  #10

                  @Mihan
                  you can combine qml and Widgets yes.

                  The classes QQuickWidget and QQuickView are specifically made for that purpose.

                  Atm, to my knowledge, there's no official way to create embeded QWidgets into QML.

                  So only QML components in QWidgets


                  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.

                  MihanM 1 Reply Last reply
                  2
                  • sierdzioS sierdzio

                    Hm ok that looks simple enough. Only small optimization I'd suggest is for DisplayRole:

                    const auto &item = m_LogList.at(index.row());
                    return item.LogTime.toString("yyyy.MM.dd hh:mm") + item.LogDesp;
                    

                    to avoid traversing the list twice. But I don't know any implementation details here, so it is mostly a guess.

                    Does m_LogList perform any heavy calculations, or complex data reads (SQL or something), or is it just a static list?

                    MihanM Offline
                    MihanM Offline
                    Mihan
                    wrote on last edited by
                    #11

                    @sierdzio Yep ,complex data reads. the m_Loglist is a QVector<struct LogContext>.I use Qt SQL to save the log and read them when i want to show the log.

                    1 Reply Last reply
                    0
                    • J.HilkJ J.Hilk

                      @Mihan
                      you can combine qml and Widgets yes.

                      The classes QQuickWidget and QQuickView are specifically made for that purpose.

                      Atm, to my knowledge, there's no official way to create embeded QWidgets into QML.

                      So only QML components in QWidgets

                      MihanM Offline
                      MihanM Offline
                      Mihan
                      wrote on last edited by
                      #12

                      @J.Hilk Okay, maybe I have to read some books about QML XD. Thank you love you three thousand times!!!

                      1 Reply Last reply
                      1
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #13

                        @J.Hilk said in How can I improving performance when I use QListView with large numbers of items:

                        Atm, to my knowledge, there's no official way to create embeded QWidgets into QML.

                        There's KDAB's DeclarativeWidgets which might be of some help.

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        MihanM 1 Reply Last reply
                        1
                        • SGaistS SGaist

                          @J.Hilk said in How can I improving performance when I use QListView with large numbers of items:

                          Atm, to my knowledge, there's no official way to create embeded QWidgets into QML.

                          There's KDAB's DeclarativeWidgets which might be of some help.

                          MihanM Offline
                          MihanM Offline
                          Mihan
                          wrote on last edited by
                          #14

                          @SGaist Hi SGaist
                          I found the Listview showed nothing few second if the layoutmode is batched.So I want to add a loading gif to make it .......Uh, you know that? Like the reflash of web and so on. But I can't find some signals or event about update, just it has a updatelater event when i used eventfiler to show all events. Could you give me a hand?
                          Thank you so much!

                          1 Reply Last reply
                          0
                          • SGaistS Offline
                            SGaistS Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on last edited by
                            #15

                            How many items are you loading ?

                            Interested in AI ? www.idiap.ch
                            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                            MihanM 1 Reply Last reply
                            0
                            • SGaistS SGaist

                              How many items are you loading ?

                              MihanM Offline
                              MihanM Offline
                              Mihan
                              wrote on last edited by
                              #16

                              @SGaist I added 10000 items for test. Cus it need to run on ARM.

                              1 Reply Last reply
                              0
                              • SGaistS Offline
                                SGaistS Offline
                                SGaist
                                Lifetime Qt Champion
                                wrote on last edited by
                                #17

                                Depending on what you are going to do with these items, you will likely need to implement things like windowing to avoid having uselessly too many items in memory.

                                Interested in AI ? www.idiap.ch
                                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                1 Reply Last reply
                                1

                                • Login

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • Users
                                • Groups
                                • Search
                                • Get Qt Extensions
                                • Unsolved