Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved QListWidget with dynamic icons

    General and Desktop
    qlistwidget qlistwidgetitem icon
    2
    12
    4528
    Loading More Posts
    • 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.
    • H
      Harry123 last edited by

      I would like to have a QListWidget with many items, each containing text and icon in the standard manner. The text identifies the icon, meaning that the icon can be retrieved by using the text as the key.

      My problem is that retrieving the icons is a relatively slow operation. Setting up the QListWidget would be much faster if I could only supply the text-part when initially creating the QListWidgetItem, later adding the icons only for the items that are really going to be displayed.

      Is there a method by which I could intercept the display of a QListWidgetItem and add the icon just before the item is displayed?

      I know that I can do this using QListView, but QListWidget already does much of the needed work.

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi,

        What about delegating the icon load to anther thread and then signal a data change when they are ready ?

        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 Reply Quote 0
        • H
          Harry123 last edited by Harry123

          I would really prefer to avoid creating icons that will never be looked at, if possible.
          I might find myself creating 1000 icons, while the user will never look at more than the first few screens.

          1 Reply Last reply Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            Sorry, I just saw that my suggestion is incomplete. Your model should be queried when needed for the icons so what I was suggesting is that when one is queried, you start loading it and then trigger the dataChanged signal.

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

            H 1 Reply Last reply Reply Quote 0
            • H
              Harry123 @SGaist last edited by

              @SGaist

              Could you please add more details about this procedure.
              I never used model/view.

              1 Reply Last reply Reply Quote 0
              • SGaist
                SGaist Lifetime Qt Champion last edited by

                Which part would like to have more detail on ?

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

                H 1 Reply Last reply Reply Quote 0
                • H
                  Harry123 @SGaist last edited by Harry123

                  @SGaist

                  I would prefer to use QListWidget, because it is much simpler than using model/view with which I have no experience.
                  I need some pointers as to what should be done - classes and functions to call.

                  I myself was thinking more in the direction of connecting to the vertical scrollbar of QListWidget and anticipating scrolls, but I'm not sure I would guess correctly from the scroll events exactly which items will be displayed.

                  1 Reply Last reply Reply Quote 0
                  • SGaist
                    SGaist Lifetime Qt Champion last edited by

                    If you use QListWidget then you don't have any control over the model so you won't be able to move the image loading part outside of it.

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

                    H 1 Reply Last reply Reply Quote 0
                    • H
                      Harry123 @SGaist last edited by

                      @SGaist

                      I have basically given up on using QListWidget that efficiently.

                      1 Reply Last reply Reply Quote 0
                      • SGaist
                        SGaist Lifetime Qt Champion last edited by

                        What option did you choose ?

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

                        H 1 Reply Last reply Reply Quote 0
                        • H
                          Harry123 @SGaist last edited by

                          @SGaist

                          I have divided the list into sections, and modified the UI to show only one section at a time.
                          This solved the performance problem (and maybe even made the UI more user-friendly).

                          1 Reply Last reply Reply Quote 0
                          • SGaist
                            SGaist Lifetime Qt Champion last edited by

                            It's good when it's more friendly :)

                            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 Reply Quote 1
                            • First post
                              Last post