qt qscroller 滚动区域,在里面动态增加组件时,增加的组件会覆盖之前组件,增加的组件也会重叠

使用qt qscroller 滚动区域,在里面动态增加组件时,增加的组件会覆盖之前组件,增加的组件也会重叠。

使用designer 拖得qscroller ,scroller-area自带一个scroller_area_content得widget,这个widget我使用水平布局layout,出现问题得原因时layout的大小不能自动更新,scroller-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 contents of the layout. In such cases, setting

the layout's size constraint property to one which provides

constraints on the minimum and/or maximum size of the layout (e.g.,

QLayout::SetMinAndMaxSize) will cause the size of the scroll area to

be updated whenever the contents of the layout changes.

复制代码
layout->setSizeConstraint(QLayout::SetMinimumSize	)

在当前ui的构造函数中加上以上代码解决

Constant Value Description

QLayout::SetDefaultConstraint 0 The main widget's minimum size is set to minimumSize(), unless the widget already has a minimum size.

QLayout::SetFixedSize 3 The main widget's size is set to sizeHint(); it cannot be resized at all.

QLayout::SetMinimumSize 2 The main widget's minimum size is set to minimumSize(); it cannot be smaller.

QLayout::SetMaximumSize 4 The main widget's maximum size is set to maximumSize(); it cannot be larger.

QLayout::SetMinAndMaxSize 5 The main widget's minimum size is set to minimumSize() and its maximum size is set to maximumSize().

QLayout::SetNoConstraint 1 The widget is not constrained.

https://doc.qt.io/qt-5/qscrollarea.html

https://doc.qt.io/qt-5/qlayout.html#sizeConstraint-prop

相关推荐
励志不掉头发的内向程序员11 分钟前
【Linux系列】掌控 Linux 的脉搏:深入理解进程控制
linux·运维·服务器·开发语言·学习
梵得儿SHI18 分钟前
Java 反射机制深度解析:从对象创建到私有成员操作
java·开发语言·class对象·java反射机制·操作类成员·三大典型·反射的核心api
沐知全栈开发21 分钟前
Foundation 折叠列表
开发语言
..Cherry..37 分钟前
【java】jvm
java·开发语言·jvm
unicrom_深圳市由你创科技1 小时前
工业上位机,用Python+Qt还是C#+WPF?
python·qt·c#
冷冷的菜哥1 小时前
go邮件发送——附件与图片显示
开发语言·后端·golang·邮件发送·smtp发送邮件
lly2024061 小时前
Linux 文件与目录管理
开发语言
计算机毕业设计木哥1 小时前
计算机毕业设计选题推荐:基于SpringBoot和Vue的爱心公益网站
java·开发语言·vue.js·spring boot·后端·课程设计
一晌小贪欢1 小时前
Python爬虫第7课:多线程与异步爬虫技术
开发语言·爬虫·python·网络爬虫·python爬虫·python3
ftpeak1 小时前
《Cargo 参考手册》第二十二章:发布命令
开发语言·rust