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

相关推荐
一条破秋裤4 分钟前
C-数据类型
c语言·开发语言·chrome
君顾19 分钟前
从0到1课后辅导管理系统开发实战:需求文档、架构设计全复盘
java·开发语言
神仙别闹10 分钟前
基于C++ MFC RSA 实现加密程序
开发语言·c++·mfc
增量星球26 分钟前
一个 Python 脚本 + LLM 怎么替代向量检索?ProjQA 技能架构原理深度解析
开发语言·python·架构·embedding·skill
探数API小喇叭43 分钟前
基站查询 API 怎么用?LAC、CELLID 参数详解与实战】
java·开发语言·api·基站定位
Mr.Lu ‍1 小时前
C++开发,使用openCV API对图片进行压缩
开发语言·c++·opencv
z落落1 小时前
C# WinForm NModbus 串口通信+WinForm Modbus4 串口通信
开发语言·单片机·c#
Mojitocean1 小时前
Win开发环境配置(持续更新)
开发语言·python
CoderIsArt1 小时前
C#环境中部署MQTT客户端
开发语言·c#
HugoStudio_SWAN2 小时前
【按键反馈】C++ 实现键盘烟花秀
开发语言·c++·学习·程序人生