当前位置:网站首页>Qt QScrollArea
Qt QScrollArea
2022-07-02 22:54:00 【Mr.codeee】
1. brief introduction
QScrollArea Class provides a scrolling view . The scrolling area is used to display the contents of the sub components in the frame . If the widget exceeds the size of the frame , The view can provide scroll bars , So that you can see the entire area of the child widget . Subassemblies must use setWidget() Appoint .
Easy to use :
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. Common methods
| QWidget *widget() const | Get the part of the scrolling area |
| QWidget *takeWidget() | Remove the widget from the scrolling area , And pass the ownership of the widget to the caller . |
| void ensureVisible(int x, int y, int xmargin = 50, int ymargin = 50) | Make sure that the contents of a certain area in the viewport are visible |
| void setAlignment(Qt::Alignment) | Set alignment |
3. Example

Source code :
QScrollArea *scrollArea = new QScrollArea;
scrollArea->setBackgroundRole(QPalette::Dark); // Set background color
QWidget *widget = new QWidget;
QVBoxLayout *layout = new QVBoxLayout; // Set vertical layout
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); // Set fixed height
t2->setFixedHeight(300);
t3->setFixedHeight(300);
layout->addWidget(t1);
layout->addWidget(t2);
layout->addWidget(t3);
scrollArea->setWidget(widget);
ui->verticalLayout->addWidget(scrollArea);
边栏推荐
- 【喜欢的诗词】好了歌
- Introduction and response to high concurrency
- Utilisation de simpletk - 4. Question étrange
- [chestnut sugar GIS] ArcMap - how to batch modify the font, color, size, etc. of annotation elements
- PHP implements querying the data matching the date of birth according to the entered age
- Based on asp Net (used mobile phone sales management system) +asp Net+c # language +vs2010+ database can be used for course design and post design learning
- 杰理之如何测试按键的误触率【篇】
- Array advanced improvement
- [ODX studio edit PDX] -0.1- how to quickly view the differences in supported diagnostic information between variant variants (service, sub function...)
- Source code analysis - lightweight asynchronous crawler framework Ruia
猜你喜欢

百度智能云-创建人脸识别应用

Performance optimization - rigorous mode

图形视图框架

Addition, deletion, modification and query of handwritten ORM (object relationship mapping)

Jatpack------LiveData

Niuke: Dragon and dungeon games

Simpleitk use - 4 Strange question

牛客网:最大子矩阵
![[LeetCode] 反转字符串中的单词 III【557】](/img/72/d3e46a820796a48b458cd2d0a18f8f.png)
[LeetCode] 反转字符串中的单词 III【557】

Higher order operation of bits
随机推荐
PHP implements querying the data matching the date of birth according to the entered age
To myself who is about to work
牛客网:龙与地下城游戏
Jerry's charge unplugged, unable to touch the boot [chapter]
[foreign journal] sleep and weight loss
杰理之充电拔出,无法触摸开机【篇】
[LeetCode] 反转字符串中的单词 III【557】
【板栗糖GIS】arcmap—为什么使用自定义捕捉的时候,经典捕捉的勾要去掉呢?
The kth largest element in the [leetcode] array [215]
地方经销商玩转社区团购模式,百万运营分享
P1007 独木桥
送给即将工作的自己
U++ learning notes - relaxation
Socket socket c/s end process
Golang面试整理 三 简历如何书写
杰理之如何测试按键的误触率【篇】
[Luogu p1541] tortoise chess [DP]
Unity publishes a method of webgl playing sound
Mathematical modeling -- graph and network models and methods (I)
[LeetCode] 存在重复元素【217】