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

相关推荐
wwww.wwww1 分钟前
qt程序执行时报错:无法定位程序输入点,但是通过IDE的run又可以正常的运行。
开发语言·ide·qt
森G1 小时前
11、交叉编译Opencv----------Opencv移植Arm
qt
乌鸦乌鸦你的小虎牙3 小时前
qt 5.12.8 配置报错(交叉编译环境)
开发语言·数据库·qt
feifeigo1233 小时前
Leslie人口模型MATLAB实现(中长期人口预测)
开发语言·matlab
写代码的二次猿3 小时前
安装openfold(顺利解决版)
开发语言·python·深度学习
一只大袋鼠4 小时前
Redis 安装+基于短信验证码登录功能的完整实现
java·开发语言·数据库·redis·缓存·学习笔记
※DX3906※4 小时前
Java排序算法--全面详解面试中涉及的排序
java·开发语言·数据结构·面试·排序算法
森G5 小时前
8、交叉编译x264----------Opencv移植Arm
qt
笨笨马甲5 小时前
Qt QSS使用指南
开发语言·qt
We་ct6 小时前
LeetCode 77. 组合:DFS回溯+剪枝,高效求解组合问题
开发语言·前端·算法·leetcode·typescript·深度优先·剪枝