当前位置:网站首页>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 .
边栏推荐
- 应用系统中的报表开发成本值多少?
- [circuit design] convert AC AC to DC
- autoware中ndtmatching功能加载点云图坐标系修正的问题
- Mathematical modeling -- red wine quality classification
- Leetcode exercise - Sword finger offer 45. arrange the array into the smallest number
- ES6 语法扩展
- iVX低代码平台系列详解 -- 概述篇(二)
- Mathematical modeling -- the laying of water pipes
- Feynman learning method (symbol table)
- 连PostgreSQL问题:expected authentication request from server, but received v
猜你喜欢

Pointer - golden stage

Implementation of 10m multifunctional signal generator with FPGA

Motionlayout -- realize animation in visual editor

IDEA 连接 数据库

应用系统中的报表开发成本值多少?

Blind separation of speech signals based on ICA and DL

Lm13 morphological quantification momentum period analysis

In 2022, the official data of programming language ranking came, which was an eye opener

基于对象的实时空间音频渲染丨Dev for Dev 专栏

Using local cache + global cache to realize user rights management of small systems
随机推荐
Mathematical modeling -- the laying of water pipes
RGBD点云降采样
点击按钮,下滑到指定的位置
mobile-picker.js
QT source code analysis -- QObject (4)
[cloud native and 5g] micro services support 5g core network
iVX低代码平台系列详解 -- 概述篇(二)
[electronic components] constant voltage, amplify the current of the load (triode knowledge summary)
解决使用ESlint时,和vetur冲突导致保存变双引号,结尾逗号等
Quanzhi t3/a40i industrial core board, 4-core [email protected] The localization rate reaches 100%
Custom MVC principle and framework implementation
Lm13 morphological quantification momentum period analysis
Mathematical modeling -- bus scheduling optimization
"Wei Lai Cup" 2022 Niuke summer multi school training camp 3, sign in question cajhf
Leetcode/ and continuous shortest subarray greater than or equal to target
2022.7.28-----leetcode.1331
JVM memory overflow online analysis dump file and online analysis open.Hprof file to get JVM operation report how jvisualvm online analysis
自定义mvc原理和框架实现
试着换个角度理解低代码平台设计的本质
Understand the clock tree in STM32 in simple terms