-
需求分析:(练习开发一个向导用户界面)
— 在同一个界面上展示不同的向导页面
— 通过 上一步 和 下一步 按钮进行切换
— 不同页面上的 元素组件 和 组件排布 都不相同
— 页面中的组件通过布局管理器进行排布 -
解决方案(通过布局嵌套进行界面设计)
其实这种东西本质只有一个页面,只是通过QStackedLayout
这个页面布局通过槽函数来切换页面。
-
通过
QStackLayout
管理不同的页面
-
通过子组件的方式生成不同的页面
widget.h
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QPushButton>
#include <QLabel>
#include <QLineEdit>
#include <QStackedLayout>
class Widget : public QWidget
{
Q_OBJECT
private:
QStackedLayout slayout;
QPushButton PreBtn;
QPushButton NextBtn;
QLabel label1;
QLabel label2;
QLabel label3;
QLabel label4;
QLineEdit edit;
QPushButton btn1;
QPushButton btn2;
void initControl();
QWidget* get1stPage();
QWidget* get2ndPage();
QWidget* get3rdPage();
private slots:
void PreBtnClicked();
void NextBtnClicked();
public:
Widget(QWidget *parent = nullptr);
~Widget();
};
#endif // WIDGET_H
widget.cpp
#include "Widget.h"
#include <QVBoxLayout>
#include <QHBoxLayout>
#include