Pyqt QMdiSubWindow使用可变数量的小部件调整大小

时间:2015-06-24 11:02:37

标签: python qt python-2.7 pyqt pyqt4

我有一个包含几个小部件的QMdiSubWindow。其中一个小部件是带有QGridLayout()的QWidget,它可以包含在运行时确定的任意数量的子小部件(最初没有)。当网格布局中的子窗口小部件数量发生变化时,我似乎无法研究如何让MDISubWindow自动调整大小。我应该在某个地方重新实施sizeHint()吗?即在主窗口小部件或子窗口小部件中?

当我用鼠标拖动调整大小手柄时,QMdiSubWindow调整大小并按住以显示正确的大小。

我尝试在小部件和QMdiSubWindow上调用.resize().updateGeometry(),但它显然不起作用。任何线索都会非常感激。

1 个答案:

答案 0 :(得分:1)

@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.