当前位置:网站首页>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);
边栏推荐
- 【板栗糖GIS】arcscene—如何做出有高度的高程图
- Methods of adding styles to native JS
- [LeetCode] 多数元素【169】
- 钟薛高回应产品1小时不化:含固体成分 融化不能变成水
- Xiaopeng P7 had an accident and the airbag did not pop up. Is this normal?
- 【板栗糖GIS】arcmap—如何批量修改注记要素的字体,颜色,大小等
- [leetcode] reverse string [344]
- Notes on key vocabulary in the English original of the biography of jobs (10) [chapter eight]
- Leetcode circular linked list (fast and slow pointer) code line by line interpretation
- Dynamic memory allocation (malloc calloc realloc free)
猜你喜欢
Graphic view frame
Dynamic memory allocation (malloc calloc realloc free)
建立自己的网站(22)
Jatpack------LiveData
对象与对象变量
wait解决僵尸进程
Socket套接字C/S端流程
Kubernetes uses the host name to allocate the pod on the specified node
Task and privilege level protection
Hanging mirror security won four global infosec awards on rsac2022
随机推荐
Zhong Xuegao responded that the product will not melt for 1 hour: it contains solid components and cannot melt into water
PHP optimizes SQL queries in foreach
地方经销商玩转社区团购模式,百万运营分享
Performance optimization - rigorous mode
Oracle-PL/SQL编程
Simpleitk use - 4 Strange question
U++ 学习笔记 堆
Niuke: Dragon and dungeon games
Jatpack------LiveData
【洛谷P1541】乌龟棋【DP】
Film and television excerpts
What is the'function'keyword used in some bash scripts- What is the 'function' keyword used in some bash scripts?
手写ORM(对象关系映射)增删改查
数组进阶提高
[leetcode] number of palindromes [9]
JS syntax ES6, ES7, es8, es9, ES10, es11, ES12 new features (Abstract)
To myself who is about to work
U++ learning note pile
Graphic view frame
#include errors detected. Please update your includePath.