当前位置:网站首页>QT qstackedwidget multi interface switching
QT qstackedwidget multi interface switching
2022-07-29 02:19:00 【Mubai 001】
sketch
QStackedWidget Inherited from QFrame.
QStackedWidget Class provides a layout for multi page switching , You can only see one interface at a time .
QStackedWidget Can be used to create similar QTabWidget The user interface provided .
Use
One QStackedWidget You can use some sub pages to fill .
effect

Source code
QPushButton *pButton = new QPushButton(this);
QLabel *pFirstPage= new QLabel(this);
QLabel *pSecondPage = new QLabel(this);
QLabel *pThirdPage = new QLabel(this);
m_pStackedWidget = new QStackedWidget(this);
pButton->setText(QStringLiteral(" Click to switch "));
pFirstPage->setText(QStringLiteral(" One go, two three li "));
pSecondPage->setText(QStringLiteral(" Youth is not old , Struggle is more than !"));
pThirdPage->setText(QStringLiteral(" The beauty of pure open source , Interesting 、 interesting 、 By spectrum ..."));
// Add a page ( For switching )
m_pStackedWidget->addWidget(pFirstPage);
m_pStackedWidget->addWidget(pSecondPage);
m_pStackedWidget->addWidget(pThirdPage);
QVBoxLayout *pLayout = new QVBoxLayout();
pLayout->addWidget(pButton, 0, Qt::AlignLeft | Qt::AlignVCenter);
pLayout->addWidget(m_pStackedWidget);
pLayout->setSpacing(10);
pLayout->setContentsMargins(10, 10, 10, 10);
setLayout(pLayout);
// Connect the switch button signal to the slot
connect(pButton, &QPushButton::clicked, this, &MainWindow::switchPage);
// Switch pages
void MainWindow::switchPage()
{
int nCount = m_pStackedWidget->count();
int nIndex = m_pStackedWidget->currentIndex();
// Get the index of the next page to be displayed
++nIndex;
// When the page index to be displayed is greater than or equal to the total page , Switch to home page
if (nIndex >= nCount)
nIndex = 0;
m_pStackedWidget->setCurrentIndex(nIndex);
}- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
Interface
int addWidget(QWidget * widget)
Add a page , And return the index corresponding to the page
int count() const
Get the number of pages
int currentIndex() const
Get the index of the current page
QWidget * currentWidget() const
Get the current page
int indexOf(QWidget * widget) const
obtain QWidget The index corresponding to the page
int insertWidget(int index, QWidget * widget)
In the index index Add page to location
void removeWidget(QWidget * widget)
remove QWidget page , Not deleted , Just move from the layout , So it's hidden .
QWidget * widget(int index) const
Get index index Corresponding page
The signal
void currentChanged(int index)
Launch when the current page changes ,index For the new index value
void widgetRemoved(int index)
Launch when the page is removed ,index The index value corresponding to the page
Common slot function
void setCurrentIndex(int index)
catalog index index The page is the current page
void setCurrentWidget(QWidget * widget)
Set up QWidget The page is the current page
summary
General situation , Two common ways :
according to currentWidget() To determine the current page , And then through setCurrentWidget() To set the page to be displayed .
according to currentIndex() To determine the current page index , And then through setCurrentIndex() To set the page to be displayed .
边栏推荐
- The problem of modifying the coordinate system of point cloud image loaded by ndtmatching function in autoware
- Website Collection
- Leetcode 242. valid anagram
- Verilog procedure assignment statements: blocking & non blocking
- Mathematical modeling -- cold proof simulation of low temperature protective clothing with phase change materials
- Understand the clock tree in STM32 in simple terms
- "Wei Lai Cup" 2022 Niuke summer multi school training camp 3, sign in question cajhf
- 12. < tag dynamic programming and subsequence, subarray> lt.72. edit distance
- Jetpack--了解ViewModel和LiveData的使用
- 第十五天(VLAN相关知识)
猜你喜欢
[email protected] The localization rate reaches 100%"/>Quanzhi t3/a40i industrial core board, 4-core [email protected] The localization rate reaches 100%
[electronic components] zener diode

字符流综合练习解题过程
![[simple implementation and extension of one · data | array heap]](/img/47/6f2c0d5c85cf05a24ba7adbd61e014.png)
[simple implementation and extension of one · data | array heap]

Character flow comprehensive exercise problem solving process

(arxiv-2018) reexamine the time modeling of person Reid based on video

C语言提高篇(一)

Detailed explanation of IVX low code platform series -- Overview (II)

开启TLS加密的Proftpd安全FTP服务器安装指南

Ciscn 2022 central China Misc
随机推荐
Understand the working principle of timer in STM32 in simple terms
QT learning notes -37.qregex and regular expressions
Prevent repeated clicks
忽略微信设置字体
全志T3/A40i工业核心板,4核[email protected],国产化率达100%
Leetcode/ and continuous shortest subarray greater than or equal to target
Probability Density Reweight
Complete collection of common error handling in MySQL installation
Data query of MySQL (multi table query)
ES6 syntax extension
MotionLayout--在可视化编辑器中实现动画
Lm13 morphological quantification momentum period analysis
开启TLS加密的Proftpd安全FTP服务器安装指南
[one · data | chained binary tree]
leetcode 242. Valid Anagram(有效的字母异位词)
Internet of things development -- mqtt message server emqx
2022.7.27-----leetcode.592
表单校验 隐藏的输入框 显示才校验
什么是作用域和作用域链
JS dom2 and dom3