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

相关推荐
Mortalbreeze几秒前
C++11 ---- 引用折叠、完美转发、可变模板参数、emplace系列接口
开发语言·c++
星恒随风几秒前
C++ 内存管理详解:从内存分区、malloc/free 到 new/delete
开发语言·c++·笔记·学习
object not found1 分钟前
Node.js fs 常用 API 整理:node:fs/promises、node:fs、fs 到底怎么用
开发语言·前端·javascript
C+++Python1 分钟前
C++ 常量全面讲解
java·开发语言·c++
江屿风2 分钟前
C++图论基础拓扑排序经典OJ题流食般投喂
开发语言·c++·笔记·算法·图论
芯岭技术郦4 分钟前
MS32C001‑C:极致成本 32 位 MCU
c语言·开发语言·单片机
nexustech6 分钟前
simplejson:Python JSON 处理的备用引擎
开发语言·python·其他·json
雷工笔记8 分钟前
MES系列48-MES 系统「质量管理」完整设计与实施方案
开发语言·javascript·ecmascript
ch.ju9 分钟前
Java Programming Chapter 4——The difference between overloading and overwriting.
java·开发语言
天天进步20151 小时前
Python全栈项目--基于机器学习的异常检测系统
开发语言·python·机器学习