Qt——QScrollArea滑动条不显示问题

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

在实际使用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 call QWidget::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

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值