在实际使用QScrollArea
的时候遇到过,如何缩小都不会显示滚动条的情况,查询了文档发现是忘记设置MinimumSize
只有当实际的大小 < MinimumSize
的时候, 才会显示滑动条,而许多时候QWidget
的默认MinimumSize
是0*0 因此,会出现问题。
Size Hints and Layouts
(转自Qt 官方文档)When using a scroll area to display the contents of a custom widget, it is important to ensure that the size hint of the child widget is set to a suitable value. If a standard
QWidget
is used for the child widget, it may be necessary to callQWidget::setMinimumSize()
to ensure that the contents of the widget are shown correctly within the scroll area.
If a scroll area is used to display the contents of a widget that contains child widgets arranged in a layout, it is important to realize that the size policy of the layout will also determine the size of the widget. This is especially usefu