当前位置:网站首页>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);
边栏推荐
- Baidu AI Cloud - create a face recognition application
- php优化foreach中的sql查询
- Golang面试整理 三 简历如何书写
- Oracle PL / SQL programming
- go 4種單例模式
- 数据分析学习记录--用EXCEL完成简单的单因素方差分析
- 悬镜安全在RSAC2022上斩获Global InfoSec Awards四项大奖
- UE4 UI adaptive screen
- Server response status code
- What is the'function'keyword used in some bash scripts- What is the 'function' keyword used in some bash scripts?
猜你喜欢

Baidu AI Cloud - create a face recognition application

SimpleITK使用——4. 奇怪的问题

地方经销商玩转社区团购模式,百万运营分享

Oracle cursor

`${}`的用法

Mathematical modeling -- graph and network models and methods (I)

Higher order operation of bits

Struct, bit segment, enumeration, union

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

Leetcode circular linked list (fast and slow pointer) code line by line interpretation
随机推荐
Notes on key vocabulary of the original English book biography of jobs (IX) [chapter seven]
Gas station [problem analysis - > problem conversion - > greed]
Socket套接字C/S端流程
杰理之内置短按再长按,不管长按多长时间都是短按【篇】
Graphic view frame
Mathematical modeling -- graph and network models and methods (I)
SimpleITK使用——4. 奇怪的問題
Developers share | HLS and skillfully use Axi_ Customize the master bus interface instructions and improve the data bandwidth - area exchange speed
Objects and object variables
[foreign journal] sleep and weight loss
《乔布斯传》英文原著重点词汇笔记(十)【 chapter eight】
[leetcode] number of palindromes [9]
大一学习分享
Array advanced improvement
What is the'function'keyword used in some bash scripts- What is the 'function' keyword used in some bash scripts?
【洛谷P1541】乌龟棋【DP】
'when to use const char * and when to use const char []' - when to use const char * and when to use const char []
Notes on key vocabulary in the English original of the biography of jobs (11) [chapter nine]
【板栗糖GIS】arcscene—如何做出有高度的高程图
NC50965 Largest Rectangle in a Histogram