QT如何实现QStackedWidget界面间的切换
Posted todo9351
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了QT如何实现QStackedWidget界面间的切换相关的知识,希望对你有一定的参考价值。
目的
学习如何使用 QStackedWidget 实现不同界面间的切换
步骤
1、新建工程

2、在widget.ui 中添加一个 Stacked Widget 组件

默认就有两个页面了

我的想法是,另外再做两个 ui界面,然后将此QWidget 提升为我们对应的界面即可。
3、继续弄两个 .ui 的界面

提升 默认的 QWidget


4. 弄个按键进行切换
5、代码如下
#include <QStackedWidget>
#include <QDebug>
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
ui->setupUi(this);
qDebug() << ui->stackedWidget->count();
Widget::~Widget()
delete ui;
int index = 0;
void Widget::on_pushButton_clicked()
ui->stackedWidget->setCurrentIndex(index);
index++;
if (index >= ui->stackedWidget->count())
index = 0;
效果

以上是关于QT如何实现QStackedWidget界面间的切换的主要内容,如果未能解决你的问题,请参考以下文章