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

相关推荐
上海合宙LuatOS1 分钟前
Air780EPM通过MQTT上传温湿度数据
开发语言·人工智能·物联网·junit·luatos
叼烟扛炮1 小时前
C++ 知识点08 类与对象
开发语言·c++·算法·类和对象
你不是我我7 小时前
【Java 开发日记】HTTP3 性能更好,为什么内网微服务依然多用 HTTP2?HTTP2 内网优势是什么?
java·开发语言·微服务
tjl521314_218 小时前
04C++ 名称空间(Namespace)
开发语言·c++
赏金术士8 小时前
Kotlin 数据流与单双向绑定
android·开发语言·kotlin
逻辑驱动的ken9 小时前
Java高频面试场景题25
java·开发语言·深度学习·面试·职场和发展
AI人工智能+电脑小能手10 小时前
【大白话说Java面试题】【Java基础篇】第32题:Java的异常处理机制是什么
java·开发语言·后端·面试
無限進步D12 小时前
Java 面向对象高级 接口
java·开发语言
两年半的个人练习生^_^13 小时前
Java日志框架和使用、日志记录规范
java·开发语言·开发规范
杨凯凡13 小时前
【032】排查入门:jstack、heap dump、Arthas 初识
java·开发语言·后端