当前位置:网站首页>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);
边栏推荐
- 影视随摘
- 手写ORM(对象关系映射)增删改查
- 杰理之、产线装配环节【篇】
- Oracle-PL/SQL编程
- 附加:【登录信息存储】与【登录状态校验】;(包括:总结了到目前为止,有关【登录信息存储】与【登录状态校验】的所有内容;)
- PMP项目整合管理
- 【洛谷P1541】乌龟棋【DP】
- SimpleITK使用——4. 奇怪的问题
- [autosar-dcm] - 4.3-how UDS $22 and $2e services read and write NVM data
- 'when to use const char * and when to use const char []' - when to use const char * and when to use const char []
猜你喜欢
NC50965 Largest Rectangle in a Histogram
Jielizhi, production line assembly link [chapter]
【板栗糖GIS】arcscene—如何做出有高度的高程图
Commodity information management system (C language document version)
数据分析学习记录(二)---响应曲面法及Design-Expert的简单使用
图形视图框架
Baidu AI Cloud - create a face recognition application
【板栗糖GIS】global mapper 如何通过dsm批量制作贴地等高线
【硬件】标准阻值的由来
Dynamic memory allocation (malloc calloc realloc free)
随机推荐
Leetcode circular linked list (fast and slow pointer) code line by line interpretation
高并发介绍及应对
【板栗糖GIS】arcmap—为什么使用自定义捕捉的时候,经典捕捉的勾要去掉呢?
Introduction and response to high concurrency
kubernetes 使用主机名将 pod 分配在指定节点上
大一学习分享
Golang's learning route
php优化foreach中的sql查询
go 多线程数据搜索
[LeetCode] 数组中的第K个最大元素【215】
Jerry's modification does not require long press the boot function [chapter]
UE4 game architecture learning notes
用sentinel熔断比例阈值改不了,设置慢调用比例没效果
数组进阶提高
NC50965 Largest Rectangle in a Histogram
Oracle-PL/SQL编程
Addition, deletion, modification and query of handwritten ORM (object relationship mapping)
Task and privilege level protection
【喜欢的诗词】好了歌
JS syntax ES6, ES7, es8, es9, ES10, es11, ES12 new features (Abstract)