Main window grows because it's the goal of using layouts. Layouts make size requirements for their widgets to ensure that all content is displayed correctly. Requirements depend on child widgets. For example, QLabel
by default grows horizontally and require space to fit its content. There are many ways to prevent window growing, and the resulting behavior varies:
- You can put
QLabel
in aQScrollArea
. When label's text is too long, scrollbars will appear. - You can enable word wrap using
self.lbl2.setWordWrap(True)
. As long as you set text with some spaces,QLabel
will display it in several lines, and window will grow vertically a bit instead of growing horizontally. - You can ignore
QLabel
's size hint usingself.lbl2.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Fixed)
.QLabel
's content will not affect its layout or parent widget size. Too large text will be truncated.