How can I make all widgets shrink if one of their children changes height?
They expand if the new height is greater, but do not decrease if they are smaller.
I tried updateGeometry(), but didn’t change anything.
Here is an example, after the child element shran, the height of the parents does not change:

import sys
from PyQt4.QtGui import *
class MainWindow(QWidget):
def __init__(self, parent=None):
QWidget.__init__(self, parent)
self.widget = QGroupBox('inner')
vbox_inner = QVBoxLayout(self.widget)
button1 = QPushButton('100')
button1.clicked.connect(lambda: self.change_height(100))
vbox_inner.addWidget(button1)
button2 = QPushButton('200')
button2.clicked.connect(lambda: self.change_height(200))
vbox_inner.addWidget(button2)
vbox = QVBoxLayout(self)
vbox.addWidget(self.widget)
def change_height(self, height):
self.widget.setFixedHeight(height)
app = QApplication(sys.argv)
myapp = MainWindow()
myapp.show()
sys.exit(app.exec_())
Is there a way to customize all parent widgets?
answer in Python:
widget = self.parent()
while widget:
widget.adjustSize()
widget = widget.parent()
source
share