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

相关推荐
时间的拾荒人1 分钟前
Qt 界面优化:绘图详解 —— 从基础图形到图片处理
开发语言·qt·面试
MayZork19 分钟前
Qt 文件操作:QSaveFile 与 QTemporaryFile(含 QTemporaryDir)实战
开发语言·qt
北冥you鱼31 分钟前
Go 语言空接口(interface{})使用场景与最佳实践
开发语言·windows·golang
xh didida41 分钟前
Linux -- 基础IO
linux·服务器·开发语言·c++
个 人 练 习 生1 小时前
C++ string 类模拟实现:从底层理解字符串(上)
开发语言·c++·经验分享·学习·程序人生
2601_966949651 小时前
多市场量化策略的数据接口应该如何设计:从数据层架构到策略接入
开发语言·python·数据分析·pandas·量化交易·股票数据·quantdash
坤坤子吖1 小时前
C++智能指针:RAII、shared_ptr与内存泄漏
开发语言·c++·笔记·学习
奋斗的阿狸_19861 小时前
ESP32-S3 + ES7210 四通道麦克风录音上传方案
c语言·开发语言·fpga开发
weixin199701080162 小时前
《1688图片空间API踩坑:img.upload 与 album.* 的防盗链与CDN缓存问题》(附Python源码)
开发语言·python·缓存
ACP广源盛139246256732 小时前
Type‑C 扩展坞方案选型笔记|国产 DP1.4 转 HDMI2.0 桥接芯片 GSV2201S @ACP评估
c语言·开发语言·笔记·硬件架构·硬件工程·国产芯片