当前位置:网站首页>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);
边栏推荐
- How should programmers write logs
- Server response status code
- Simpleitk use - 3 Common operations
- #include errors detected. Please update your includePath.
- 【板栗糖GIS】global mapper 如何通过dsm批量制作贴地等高线
- [leetcode] reverse string [344]
- 佩服,竟然有人把高等数学这么晦涩难懂的科目,讲解得如此通俗易懂
- go 4種單例模式
- The threshold value of fusing proportion cannot be changed with sentinel, and setting the slow call proportion has no effect
- Build your own website (22)
猜你喜欢
![[foreign journal] sleep and weight loss](/img/81/42dcfae19e72a0bc761cb7a40fe5d5.jpg)
[foreign journal] sleep and weight loss

`${}`的用法

【板栗糖GIS】arcmap—如何批量修改注记要素的字体,颜色,大小等

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

Commodity information management system (C language document version)
![[LeetCode] 多数元素【169】](/img/72/d3e46a820796a48b458cd2d0a18f8f.png)
[LeetCode] 多数元素【169】

NC50965 Largest Rectangle in a Histogram

Oracle-游标

SimpleITK使用——3. 常见操作

Jatpack------LiveData
随机推荐
Storage unit conversion
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
uniapp微信登录返显用户名和头像
PMP项目整合管理
SimpleITK使用——4. 奇怪的問題
Addition, deletion, modification and query of handwritten ORM (object relationship mapping)
Oracle-PL/SQL编程
Commodity information management system (C language document version)
UE4 UI自适应屏幕
数学建模——图与网络模型及方法(一)
加油站[问题分析->问题转换->贪心]
数据分析学习记录(二)---响应曲面法及Design-Expert的简单使用
性能优化----严苛模式
杰理之内置关机电流 1.2uA,之后不能长按开机【篇】
Hanging mirror security won four global infosec awards on rsac2022
[chestnut sugar GIS] ArcMap - how to batch modify the font, color, size, etc. of annotation elements
Gas station [problem analysis - > problem conversion - > greed]
杰理之样机在多次触摸后会触发关机【篇】
Mathematical modeling -- graph and network models and methods (I)
Source code analysis - lightweight asynchronous crawler framework Ruia