当前位置:网站首页>Qt滚动区域QScrollArea
Qt滚动区域QScrollArea
2022-06-21 20:37:00 【贝勒里恩】
一、前言
在软件开发中,软件中经常有些区域是动态布局的,这就让你很难预测该区域的大小,在布局时就不能将其大小固定死,滚动区域就发挥了很大的用处,使用滚动区域,就算动态布局,也可以可大可小。
二、效果展示

三、详解
QScrollArea实际是一个嵌套容器,它由两部分组成:scrollArea、scrollAreaWidgetContents;
- scrollArea是滚动区域;
- scrollAreaWidgetContents是内部容器;
- 当QScrollArea的尺寸 < 内部容器的尺寸时,就会出现滚动条(横纵都适用);
- 使用ui edit拖拽一个QScrollArea时,会自动new一个内部容器,但是使用代码生成QScrollArea时,一定要自己设置内部容器;
- 设置内部容器使用setWidget(QWidget*)接口;
- Tips:设置内部容器,最好在内部容器部件已经布局好之后,最好将其附到滚动区域里去(官方文档建议);
四、示例代码
QScrollArea* scrollArea = new QScrollArea(this);
QWidget* scrollWidget = new QWidget(this);
QVBoxLayout* layout_scrollWidget = new QVBoxLayout(scrollWidget);
layout_scrollWidget->setMargins(0);
layout_scrollWidget->setSpacing(0);
...
layout_scrollWidget->addWidget(xxx);
...
scrollArea_example->setWidget(scrollArea_widget); //给ScrollArea添加内部部件
scrollArea_example->setWidgetResizable(true); //自动调整大小
边栏推荐
- Jeu de boutons de force 4 (version MySQL)
- 如何卸载用conda命令安装的包
- Dategridview first column sort
- Characteristics and experimental suggestions of abbkine cell cycle Staining Kit
- 技术分享 | MySQL:caching_sha2_password 快速问答
- How to write the title of popular popular items in our media video
- GDB调试实战(10)多线程调试
- class path resource [classpath*:mapper/*.xml] cannot be opened because it does not exist
- 软件架构介绍
- Lifting method (Part 2) lifting tree
猜你喜欢

Beijing accelerates ecological construction, Medtronic Internet and Moore thread complete product compatibility and mutual certification

HiCPlotter|HiC数据可视化工具
![[in depth understanding of tcapulusdb technology] tcapulusdb business data backup](/img/7f/6d42dc96348001dd6ebd724a44a123.png)
[in depth understanding of tcapulusdb technology] tcapulusdb business data backup

HiC-Pro | HiC数据处理工具

HIC Pro | HIC data processing tool

Chess and card games

Technology sharing | introduction to kubernetes pod

【深入理解TcaplusDB技术】一键安装Tmonitor后台
![[in depth understanding of tcapulusdb technology] tcapulusdb construction data](/img/64/4d7ec393d8469cdadc89078a8cf4b1.png)
[in depth understanding of tcapulusdb technology] tcapulusdb construction data

刷题笔记(十七)--二叉搜索树:关于属性问题
随机推荐
I2C [2] - why does IIC need to use open drain output and pull-up resistor bug
class path resource [classpath*:mapper/*.xml] cannot be opened because it does not exist
秒懂微服务
Self made C compiler
Notes on topic brushing (16) -- binary tree: modification and construction
[leetcode] 8. String conversion integer (ATOI)
Thresholdtypes of opencvsharp threshold segmentation threshold function
利用for循环,分别计算1-100中奇数的和、偶数的和【方法一】
Introduction to software architecture
线粒体基因组常见缩写与术语
[in depth understanding of tcapulusdb technology] tcapulusdb business data backup
采样器合集
Technology sharing | a clustering incremental statistical SQL requirement in MySQL
利用do while循环,分别计算1-100中奇数的和、偶数的和【方法二】
实验二 栈和队列
UEFI dual system + dual hard disk installation
Enterprise data leakage prevention solution sharing
Use the for loop to calculate the odd and even sums in 1-100 [method 2]
使用StreamAPI 断言组合,结合本地缓存做模糊查询(比mysql效率提升近1000倍)
关于eureka启动成功但是访问404问题