Hello,

I'm currently using PySide2, Qt 5.12.0

I implemented something like a tree structure, using a QGridLayout. The rows of the tree consist of 5-10 widgets, which are mostly labels. But I might have dozens or hundreds of rows in that layout. Most of them are hidden, but the tree and sub trees can be expanded, sometimes showing hundreds of widgets in one go.

As far as I understand, for each widget.setVisible(True) call, the layout is invalidated and corrected, which leads to a substantial slowdown in the seconds. I worked around that, by setting a QTimer on the setGeometry method of the QGridLayout, reseting the timer every time a call is made and only after 20ms of "silence" is the actual setGeometry called by me.

That works reasonably well, except, that in those 20ms and for a bit longer, the widgets are shown in their old place - sometimes at (0, 0) if they are shown the first time - and block the rest of the widgets. I figure, since I block their placement with my workaround, they are just shown wherever they happen to be with whatever size they happen to have.

Delaying the paint event doesn't work for me, since their child widgets receive their own paint events, independently and even if not, the background, which is done using the QPalette, is also independent of the paint event.

I also read about Qt::WA_WState_ExplicitShowHide, but I'm not quite sure, if this would help me in this situation.

So I have a few questions:

Is the slowdown of several seconds in a QGridLayout with ~100 visible Widgets to be expected, or am I doing something wrong (on top of implementing a tree structure this way)?
Is there a way to tell the layout to hang tight until all the widgets are set to visible and the widgets to stay hidden, until the layout has moved them correctly?
Is the slowdown caused by the widgets needing to size themselves, or by the layout needing to move them around?
Is there an alternative layout strategy, that could support my type of use case, or is that just out of the realm of possibility?

I didn't use a TreeView, because I wanted every sub tree to have their own header and field positions.

I hope I described everything well enough, that code won't be necessary, since it would be a lot.