QT界面基本操作(QListWidget、QStackedWidget、QSplitter)

这篇博客详细介绍了如何使用QT进行界面设计,包括堆栈布局的创建,BASEINFO、contact和detail等界面的编写。重点讲述了在main函数中如何利用QSplitter分割窗口,并将QListWidget与QStackedWidget有效连接,实现不同界面之间的切换。此外,还展示了程序的最终截图。
摘要由CSDN通过智能技术生成

content(堆栈窗体编写)

堆栈布局

//.h
#ifndef CONTENT_H
#define CONTENT_H

#include <QFrame>
#include <QDialog>
#include <QStackedWidget>
#include <QPushButton>
#include "baseinfo.h"
#include "contact.h"
#include "detail.h"

class content : public QFrame
{
   
    Q_OBJECT

public:
    content(QWidget *parent = 0);
    ~content();
    QStackedWidget *stack;//堆栈窗体
    QPushButton *AmendBtn;
    QPushButton *CloseBtn;
    BaseInfo *baseinfo;//基本信息界面
    Contact *contact;//联系方式界面
    Detail *detail;//详细资料

};

#endif // CONTENT_H

//.cpp
#include "content.h"
#include <QHBoxLayout>

content::content(QWidget *parent) : QFrame(parent)
{
   
    stack =new QStackedWidget(this);
    stack->setFrameStyle(QFrame::Panel|QFrame::Raised);
    baseinfo=new BaseInfo();
    contact=new Contact();
    detail=new  Detail();
    stack->addWidget(baseinfo);
    stack->addWidget(contact);
    stack->addWidget(detail);
    AmendBtn=new QPushButton(tr("修改"));
    CloseBtn=new QPushButton(tr("关闭"));
    QHBoxLayout *BtnLayout=new QHBoxLayout;
    BtnLayout->addStretch(1);//拉伸
    BtnLayout->addWidget(AmendBtn);
    BtnLayout->addWidget(CloseBtn);
    QVBoxLayout *RightLayout=new QVBoxLayout(this);
    RightLayout->setMargin(10);//边距
    RightLayout->setSpacing(6);//键距
    RightLayout->addWidget(stack);
    RightLayout->addLayout(BtnLayout);
}

content::~content()
{
   

}

BASEINFO(基本信息界面编写)

//.h
#ifndef BASEINFO_H
#define BASEINFO_H

#include <QWidget>
#include <QLabel>
#include <QLineEdit>
#include <QComboBox>
#include <QTextEdit>
#include <QGridLayout>
#include <QPushButton>

class BaseInfo : public QWidget
{
   
    Q_OBJECT
public:
    explicit BaseInfo(QWidget *parent = nullptr);

signals:

public slots:
private:
    QLabel *UserNamelabel;
    QLabel *Namelabel;
    QLabel *Sexlabel;
    QLabel *Departmentlabel;
    QLabel *Agelabel;
    QLabel *Otherlabel;
    QLineEdit *UserNameLineEdit;
    QLineEdit *NameLineEdit;
    QComboBox *SexComboBox;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值