0

I am working on a Qt-UI with PyQt and found this nice snipped to create a custom collapsible box widget here: How to create collapsible box in PyQt I have just replaced the internal QScrollArea by a QFrame.

It works perfectly, as long as the content of the layout that is added stays the same. However, I allow the user to add or remove widgets from that layout dynamically during use. Here I need some help. I am adding a Grid Layout with, say, 3 widgets inside there (initial creation of the box with .setContentLayout) and once the user adds a 4th widget:

  • the layout is compressed and keeps its original size
  • all widgets inside are compressed to fit in the newly created one
  • overall size of the collapsible box is kept constant.

I have played with various options like updateGeometry() on the content_area and all surounding widgets. It seems I don't fully understand what this code does, I am not really familiar with these animations yet. My best guess is, that the animation somehow blocks the update of the height of the collapsible box, causing the layout to be compressed. I would be really happy for a pointer where to look / what to adjust to get the size of the collapsible box reacting to the size of the containing layout.

Thanks!

Atd
  • 21
  • 4
  • The animation itself doesn't block anything: if you carefully study that code, you'll find that the animation sets a fixed height for the container widget. If you want to make it dynamic and allow adding and removing elements, you need to recompute the heights as it's done in `setContentLayout` and eventually update the maximum height if the widget is not collapsed. It would really help you to study how [layout managers](https://doc.qt.io/qt-5/layout.html) work and what [size hints and policies](https://doc.qt.io/qt-5/qwidget.html#size-hints-and-size-policies) are. – musicamante Jan 04 '22 at 17:06
  • Thank you I will read into it again. I have played with the policies and size hints already. E.g. the content_area has a fixed height policy. That was my inital guess to what is going wrong. I changed it to expanding, but instead of allowing the space of content_area to adjust to the child layout, it changes the behavior of the whole widget in the layout that is containing the collapsible box. I fail to understand that. – Atd Jan 05 '22 at 06:02

0 Answers0