PDA

View Full Version : QListView and Displaying QIcon



NIteLordz
10th October 2016, 18:31
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?

Ginsengelf
11th October 2016, 08:44
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

Killian
11th October 2016, 10:39
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.

NIteLordz
11th October 2016, 12:32
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.

Killian
11th October 2016, 14:06
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.

NIteLordz
11th October 2016, 14:26
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 :)

anda_skoa
11th October 2016, 18:51
Thumbnail generation can also be nicely done via QThreadPool, even potentially handling multiple images in parallel.

Cheers,
_