Results 1 to 7 of 7

Thread: QListView and Displaying QIcon

  1. #1
    Join Date
    Dec 2014
    Posts
    49
    Thanks
    6
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5 PyQt3 PyQt4
    Platforms
    Windows

    Default QListView and Displaying QIcon

    I am currently implementing a QListView that displays N QFileInfo items found via search. When i display the item, i want to display the texture of the image. To do this, i am using hte filepath to get the pixmap, and then converting into QIcon to display in teh list view.

    This works properly, however is HORRIFICLY slow to load, and to function.

    What can i do to improve performance?

    Is there a better approach to what i am trying to do?

  2. #2
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    516
    Thanks
    12
    Thanked 77 Times in 75 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QListView and Displaying QIcon

    Hi, I had a similar performance problem in a tree, and that was solved using setUniformRowHeights. Maybe QListView::setUniformItemSizes improves the performance of your program.

    Ginsengelf

  3. #3
    Join Date
    Mar 2014
    Posts
    23
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows Android

    Default Re: QListView and Displaying QIcon

    Converting from QPixmap to QImage while traversing file trees and loading data is fairly slow.
    I had to write an asset browser with a preview ability a couple of years ago and what I did was using a QItemDelegate, drawing the asset's content via QPainter but only for items currently visible in the view. Additionally I implemented a lazy loading for the item data which all in all resulted in a list view being capable of handling tens of thousands of items with smooth scrolling.

    This might be the hard way and way more work than using the item's icon but this way we never had performance issues anymore.

  4. #4
    Join Date
    Dec 2014
    Posts
    49
    Thanks
    6
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5 PyQt3 PyQt4
    Platforms
    Windows

    Default Re: QListView and Displaying QIcon

    Quote Originally Posted by Killian View Post
    Converting from QPixmap to QImage while traversing file trees and loading data is fairly slow.
    I had to write an asset browser with a preview ability a couple of years ago and what I did was using a QItemDelegate, drawing the asset's content via QPainter but only for items currently visible in the view. Additionally I implemented a lazy loading for the item data which all in all resulted in a list view being capable of handling tens of thousands of items with smooth scrolling.

    This might be the hard way and way more work than using the item's icon but this way we never had performance issues anymore.
    Thanks, will look into the QItemDelegate. Any chance you could point out a few things of how the lazy loading was accomplished? Not that this is my issue at the moment, as i am seeing it slow down with only 20 items displayed.

  5. #5
    Join Date
    Mar 2014
    Posts
    23
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows Android

    Default Re: QListView and Displaying QIcon

    Sure thing, I can line it out a bit. But keep in mind it comes out of my head, it's been a while since I touched this.

    So if I recall correctly each item in the asset list had some arbitrary data. One property contained the file path to the asset. Once an item came into view (by users scrolling the list or by "jumping" to an item from the search filters) a thread was started which read the file path from that certain item, collected its texture preview image and put into a QPixmap. During that the item showed just a busy indicator (hourglass or similar). As soon as the thread had finished preparing a preview thumbnail it emitted a signal which made the target item switch from the busy indicator to the real preview pixmap.

    You don't have to spawn a thread for each item but rather have one background thread running and doing this for all visible items. Preview images from items that moved out of sight can be kept in memory respectively serve as an image cache, but you could also free them up. Decide yourself on the latter.

    Hope this helps. Let me know if you need more details.

  6. #6
    Join Date
    Dec 2014
    Posts
    49
    Thanks
    6
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5 PyQt3 PyQt4
    Platforms
    Windows

    Default Re: QListView and Displaying QIcon

    Quote Originally Posted by Killian View Post
    Sure thing, I can line it out a bit. But keep in mind it comes out of my head, it's been a while since I touched this.

    So if I recall correctly each item in the asset list had some arbitrary data. One property contained the file path to the asset. Once an item came into view (by users scrolling the list or by "jumping" to an item from the search filters) a thread was started which read the file path from that certain item, collected its texture preview image and put into a QPixmap. During that the item showed just a busy indicator (hourglass or similar). As soon as the thread had finished preparing a preview thumbnail it emitted a signal which made the target item switch from the busy indicator to the real preview pixmap.

    You don't have to spawn a thread for each item but rather have one background thread running and doing this for all visible items. Preview images from items that moved out of sight can be kept in memory respectively serve as an image cache, but you could also free them up. Decide yourself on the latter.

    Hope this helps. Let me know if you need more details.
    This does help, i was curious if you had spawned a seperate thread to do the actual image loading. that was going to be my next approach. thanks for confirming

  7. #7
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QListView and Displaying QIcon

    Thumbnail generation can also be nicely done via QThreadPool, even potentially handling multiple images in parallel.

    Cheers,
    _

Similar Threads

  1. Replies: 2
    Last Post: 7th December 2013, 20:02
  2. QListView only displaying last item
    By Easyman in forum Qt Programming
    Replies: 1
    Last Post: 24th May 2009, 12:42
  3. QListView not displaying all directory files
    By been_1990 in forum Qt Programming
    Replies: 14
    Last Post: 8th May 2009, 02:00
  4. Displaying Multiple Columns in QListView
    By millard in forum Qt Programming
    Replies: 8
    Last Post: 5th December 2007, 13:03
  5. Replies: 2
    Last Post: 31st May 2006, 22:52

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.