mor22
mor22

Reputation: 1372

Pyqt QMdiSubWindow resize with variable number of widgets

I have an QMdiSubWindow which contains a couple of widgets. One of these widgets is a QWidget with a QGridLayout() which can contain an arbitrary number of sub-widgets which is determined at runtime (initially none). I can't seem to workout how to get the MDISubWindow to automatically resize when the number of sub-widgets in the grid layout changes. Should I be re-implementing the sizeHint() somewhere? ie in the main widget or the sub-widgets?

The QMdiSubWindow resizes fine when I drag the resize handle with the mouse and snaps to show the correct size.

I've tried calling .resize() and .updateGeometry() on both the widget and the QMdiSubWindow but It doesn't obviously work. Any clues would be much appreciated.

Upvotes: 0

Views: 697

Answers (1)

mor22
mor22

Reputation: 1372

@ekhumoro suggested I try adjustSize(), which didn't work initially. I did some more searching and ended up with the following solution which worked for me

QTimer.singleShot(1, self.parent.windows[self.uuid].adjustSize)

where

self.parent.windows[self.uuid]

is the QMdiSubWindow object. I'm guessing that just calling self.adjustSize() doesn't work because the sizeHint is not updated until the later in the event queue.

Upvotes: 1

Related Questions