1 Star 0 Fork 6

yuanmin2100/AnimateStackedWidget

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
mainwindow.cpp 2.67 KB
一键复制 编辑 原始数据 按行查看 历史
zlqzlq 提交于 2022-03-17 20:59 . init commit
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QPropertyAnimation>
#include <QParallelAnimationGroup>
#include <QVBoxLayout>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
QWidget *widget = NULL;
QVBoxLayout *layout = NULL;
QLabel *label = NULL;
// widget 1
widget = new QWidget(this);
layout = new QVBoxLayout;
label = new QLabel(tr("This is widget One"), this);
label->setAlignment(Qt::AlignCenter);
layout->addWidget(label);
widget->setLayout(layout);
widget->setStyleSheet("QWidget {font-size: 24px; color: white; background-color: red}");
ui->stackedWidget->addWidget(widget);
// widget 2
widget = new QWidget(this);
layout = new QVBoxLayout;
label = new QLabel(tr("This is widget Two"), this);
label->setAlignment(Qt::AlignCenter);
layout->addWidget(label);
widget->setLayout(layout);
widget->setStyleSheet("QWidget {font-size: 24px; color: black; background-color: yellow}");
ui->stackedWidget->addWidget(widget);
// widget 3
widget = new QWidget(this);
layout = new QVBoxLayout;
label = new QLabel(tr("This is widget Three"), this);
label->setAlignment(Qt::AlignCenter);
layout->addWidget(label);
widget->setLayout(layout);
widget->setStyleSheet("QWidget {font-size: 24px; color: white; background-color: green}");
ui->stackedWidget->addWidget(widget);
// widget 4
widget = new QWidget(this);
layout = new QVBoxLayout;
label = new QLabel(tr("This is widget Four"), this);
label->setAlignment(Qt::AlignCenter);
layout->addWidget(label);
widget->setLayout(layout);
widget->setStyleSheet("QWidget {font-size: 24px; color: black; background-color: cyan}");
ui->stackedWidget->addWidget(widget);
// widget 5
widget = new QWidget(this);
layout = new QVBoxLayout;
label = new QLabel(tr("This is widget Five"), this);
label->setAlignment(Qt::AlignCenter);
layout->addWidget(label);
widget->setLayout(layout);
widget->setStyleSheet("QWidget {font-size: 24px; color: white; background-color: blue}");
ui->stackedWidget->addWidget(widget);
m_label = new QLabel(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_btnWidget1_clicked()
{
ui->stackedWidget->switchIndex(0);
}
void MainWindow::on_btnWidget2_clicked()
{
ui->stackedWidget->switchIndex(1);
}
void MainWindow::on_btnWidget3_clicked()
{
ui->stackedWidget->switchIndex(2);
}
void MainWindow::on_btnWidget4_clicked()
{
ui->stackedWidget->switchIndex(3);
}
void MainWindow::on_btnWidget5_clicked()
{
ui->stackedWidget->switchIndex(4);
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/yuanmin2100/animate-stacked-widget.git
[email protected]:yuanmin2100/animate-stacked-widget.git
yuanmin2100
animate-stacked-widget
AnimateStackedWidget
master

搜索帮助