1

I'm working on a PyQT5 application showing a scrollable area with few to many (thousands) custom widgets.

I have cases where there could be 2000 (maybe more) of these widgets.

Each widget shows a cropped image (I can pan/zoom the image to change the crop area), a text, 2 info icons and 2 buttons (for edit/remove operations).

These widgets are all the same dimensions and style, so I styled them using QSS on the parent object in order to set the style only once at startup.

I actually added all these widgets to a ScrollableArea with a GridLayout in order to have them disposed in a grid fashion and to be able to scroll them up/down.

When resizing the window, the widgets are resized as well in order to fit the new sizes (fixed number of columns).

What happens is that when I create this UI the first time, it needs 6-8 seconds to be shown and when I resize the window, it needs 2-3 seconds to update the widgets with the new size.

The results to the user it that the application is hanging while resizing objects. And this is so annoying to me.

I profiled a bit and I saw the setStylesheet is slowing down things here because it needs to set style on all the widgets.

And here is my question: do you have any suggestion or pointers on how to implement this ScrollableArea with so many styled custom widgets without having this kind of performance issues?

Thank you in advance for any help.

shakraw
  • 39
  • 7
  • The phrase "there could be 2000 (maybe more) of these widgets" sets of alarm bells. I'd suggest you should probably consider using the [Graphics View Framework](http://doc.qt.io/qt-5/graphicsview.html) instead. – G.M. Jun 20 '18 at 08:53
  • You might as well check the answer of [this question](https://stackoverflow.com/questions/45389540/how-to-display-a-scrollable-list-with-a-substantial-amount-of-widgets-as-items-i). It explains why using QScrollArea with a lot of subclases of QWidget is a bad idea. – scopchanov Jun 20 '18 at 21:46
  • 1
    @scopchanov: I read the link you provided and it makes sense to me. Thanks. – shakraw Jun 21 '18 at 07:55
  • I'm glad it was helpful to you. If you need further help in a form of a working code, please check out [this example](https://github.com/scopchanov/CustomList). It demonstrates a scrollable list of 100024 items, but you might as well change it to another number. Each item has a text and two clickable areas - one to select the item and one to expand it in order to show more text. I hope it will be a good starting point to solve your particular task. It is written in C++, but translating it to Pyton shouldn't be a problem. – scopchanov Jun 21 '18 at 21:08

0 Answers0