当前位置:网站首页>Qt QScrollArea
Qt QScrollArea
2022-07-02 22:07:00 【Mr.codeee】
1.简介
QScrollArea类提供了滚动视图。滚动区域用于显示框架内子部件的内容。如果小部件超过了框架的大小,视图可以提供滚动条,以便可以查看子小部件的整个区域。子部件必须用setWidget()指定。
简单使用:
QLabel *imageLabel = new QLabel;
QImage image("C:\\Users\\Desktop\\image\\1.webp");
imageLabel->setPixmap(QPixmap::fromImage(image));
QScrollArea *scrollArea = new QScrollArea;
scrollArea->setBackgroundRole(QPalette::Dark);
scrollArea->setWidget(imageLabel);
ui->verticalLayout->addWidget(scrollArea);

2.常用方法
| QWidget *widget() const | 获取滚动区域的部件 |
| QWidget *takeWidget() | 移除滚动区域的小部件,并将小部件的所有权传递给调用者。 |
| void ensureVisible(int x, int y, int xmargin = 50, int ymargin = 50) | 确保视口中的一定区域内容是可见 |
| void setAlignment(Qt::Alignment) | 设置对齐方式 |
3.示例

源码:
QScrollArea *scrollArea = new QScrollArea;
scrollArea->setBackgroundRole(QPalette::Dark); //设置背景色
QWidget *widget = new QWidget;
QVBoxLayout *layout = new QVBoxLayout; //设置垂直布局
widget->setLayout(layout);
QTextEdit *t1 = new QTextEdit(widget);
QTextEdit *t2 = new QTextEdit(widget);
QTextEdit *t3 = new QTextEdit(widget);
t1->setPlaceholderText("t1");
t2->setPlaceholderText("t2");
t3->setPlaceholderText("t3");
t1->setFixedHeight(300); //设置固定高
t2->setFixedHeight(300);
t3->setFixedHeight(300);
layout->addWidget(t1);
layout->addWidget(t2);
layout->addWidget(t3);
scrollArea->setWidget(widget);
ui->verticalLayout->addWidget(scrollArea);
边栏推荐
- [leetcode] there are duplicate elements [217]
- [foreign journal] sleep and weight loss
- Jerry's modification does not require long press the boot function [chapter]
- 加油站[问题分析->问题转换->贪心]
- [LeetCode] 多数元素【169】
- JS solution for obtaining the width and height of hidden elements whose display is none
- 牛客网:龙与地下城游戏
- Rails 3 activerecord: sort by association count - rails 3 activerecord: order by count on Association
- 【AUTOSAR-DCM】-4.3-UDS $22和$2E服务如何读取和写入NVM数据
- Using rendertext() to output multiple lines of text with rendertext() in R shiny
猜你喜欢

kubernetes 使用主机名将 pod 分配在指定节点上

Performance optimization - rigorous mode

悬镜安全在RSAC2022上斩获Global InfoSec Awards四项大奖

Leetcode circular linked list (fast and slow pointer) code line by line interpretation

Developers share | HLS and skillfully use Axi_ Customize the master bus interface instructions and improve the data bandwidth - area exchange speed

Array advanced improvement

分享 10 个 JS 闭包面试题(图解),进来看看你能答对多少

【ODX Studio编辑PDX】-0.1-如何快速查看各Variant变体间的支持的诊断信息差异(服务,Sub-Function...)
![P7072 [CSP-J2020] 直播获奖](/img/bc/fcbc2b1b9595a3bd31d8577aba9b8b.png)
P7072 [CSP-J2020] 直播获奖

wait解决僵尸进程
随机推荐
傑理之修改不需要長按開機功能【篇】
Oracle PL / SQL programming
性能优化----严苛模式
图形视图框架
Jatpack------LiveData
分享 10 个 JS 闭包面试题(图解),进来看看你能答对多少
stop slave卡住--事务的事件没有复制完整
Hanging mirror security won four global infosec awards on rsac2022
PMP项目整合管理
《乔布斯传》英文原著重点词汇笔记(十)【 chapter eight】
Oracle cursor
Local dealers play the community group purchase mode and share millions of operations
Notes on key vocabulary in the English original of the biography of jobs (11) [chapter nine]
牛客网:龙与地下城游戏
uniapp微信登录返显用户名和头像
任务和特权级保护
Wait to solve the zombie process
杰理之内置短按再长按,不管长按多长时间都是短按【篇】
杰理之直接触摸样机的顶针反应不正常【篇】
《乔布斯传》英文原著重点词汇笔记(十一)【 chapter nine】