Qt-实现按钮切换页面

#include "dialog.h"
#include "ui_dialog.h"
#include "yqzregister.h"

#include <QHBoxLayout>
#include <QLabel>
#include <QPushButton>
#include <QStackedWidget>

Dialog::Dialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Dialog)
{
    ui->setupUi(this);

    this->setFixedSize(800,600);

    QListWidget list=new QListWidget(this);

    list->insertItem(0,tr("1"));
    list->insertItem(1,tr("2"));
    list->insertItem(2,tr("3"));
    list->insertItem(3,tr("4"));
    list->insertItem(4,tr("5"));
    list->insertItem(5,tr("6"));
    list->insertItem(6,tr("7"));
    list->insertItem(7,tr("8"));
  
    QLabel label2=new QLabel(tr("1"));
    QLabel label3=new QLabel(tr("2"));
    QLabel label4=new QLabel(tr("3"));
    QLabel label5=new QLabel(tr("4"));
    QLabel label6=new QLabel(tr("5"));
    QLabel label7=new QLabel(tr("6"));
    QLabel label8=new QLabel(tr("7"));
    QLabel label2=new QLabel(tr("8"));

    QStackedWidget stack=new QStackedWidget(this);

    stack->addWidget(label1);
    stack->addWidget(label2);
    stack->addWidget(label3);
    stack->addWidget(label4);
    stack->addWidget(label5);
    stack->addWidget(label6);
    stack->addWidget(label7);
    stack->addWidget(label8);

    QHBoxLayout mainLayout=new QHBoxLayout(this);
    mainLayout->setMargin(5);
    mainLayout->setSpacing(5);

    mainLayout->addWidget(list);
    mainLayout->addWidget(stack,0,Qt::AlignCenter);

    mainLayout->setStretchFactor(list,1);
    mainLayout->setStretchFactor(stack,3);


    connect(list,SIGNAL(currentRowChanged(int)),stack,SLOT(setCurrentIndex(int)));

    this->show();

}

Dialog::~Dialog()
{
    delete ui;
}
posted @ 2023-03-22 11:26  对CSDN使用炎拳吧  阅读(237)  评论(0编辑  收藏  举报