QScrollBar中的setWidgetResizable函数

背景:让滚动区域中的内容的左右随着窗口自适应,上下内容超出屏幕,出现滚动。

方法:

	widget = new QWidget;
	sWidget = new QScrollArea;
    sWidget->setWidget(widget);
    //sWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    sWidget->setWidgetResizable(true);

关键函数在于setWidgetResizable:
This property holds whether the scroll area should resize the view widget
If this property is set to false (the default), the scroll area honors the size of its widget. Regardless of this property, you can programmatically resize the widget using widget()->resize(), and the scroll area will automatically adjust itself to the new size.
If this property is set to true, the scroll area will automatically resize the widget in order to avoid scroll bars where they can be avoided, or to take advantage of extra space.

此属性保存滚动区域是否应调整视图小部件的大小
如果将此属性设置为false(默认值),则滚动区域将遵循其小部件的大小。 无论此属性如何,都可以使用widget()-> resize()以编程方式调整窗口小部件的大小,并且滚动区域将自动将其自身调整为新的大小。
如果将此属性设置为true,则滚动区域将自动调整窗口小部件的大小,以避免在可以避免滚动条的地方使用滚动条,或者利用多余的空间。

  • 5
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值