在实际使用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
QWidgetis 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 useful to know if you intend to dynamically change the c

在使用Qt的QScrollArea时,如果滚动条不显示,可能是因为没有正确设置大小提示或布局。只有当内容区域的实际大小小于QScrollArea的大小时,滚动条才会显示。设置合适的大小提示并考虑布局的大小策略,如使用QLayout时,调整布局的尺寸约束,可以确保在内容改变时更新滚动区域的大小。
最低0.47元/天 解锁文章
777

被折叠的 条评论
为什么被折叠?



