目录
效果:
整体文件:
main.cpp
baseinfo.cpp
baseinfo.h
contact.cpp
contact.h
content.cpp
content.h
detail.cpp
detail.h
加上数据库后端的功能的效果(更新:https://blog.csdn.net/qq_41895747/article/details/104200017)
原效果:
#include "content.h"
#include
#include
#include
#include
#include
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QFont font("AR PL KaitiM GB",12);//设置字体
a.setFont(font);
//新建水平分割的窗口对象作为主布局
QSplitter *splitterMain =new QSplitter(Qt::Horizontal,0);
splitterMain->setOpaqueResize(true);
QListWidget *list =new QListWidget(splitterMain); //在左侧窗口插入条目选择框
list->insertItem(0,QStringLiteral("基本信息"));
list->insertItem(1,QStringLiteral("联系方式"));
list->insertItem(2,QStringLiteral("详细资料"));
Content *content =new Content(splitterMain);
QObject::connect(list,SIGNAL(currentRowChanged(int)),content->stack,SLOT(setCurrentIndex(int))); //链接信号与槽
//设置水平分割窗口的标题
splitterMain->setWindowTitle(QStringLiteral("人事管理系统"));
//设置水平分割窗口的最小尺寸
splitterMain->setMinimumSize(splitterMain->minimumSize());
//设置水平分割窗口的最大尺寸
splitterMain->setMaximumSize(splitterMain->maximumSize());
splitterMain->show(); //显示主布局框,与上面的控件一起显示
//Content w;
//w.show();
return a.exec();
}
#include "baseinfo.h"
BaseInfo::BaseInfo(QWidget *parent) : QWidget(parent)
{
/****左侧****/
UserNameLabel =new QLabel(QStringLiteral("用户名"));
UserNameLineEdit =new QLineEdit;
NameLabel =new QLabel(QStringLiteral("姓名:"));
NameLineEdit =new QLineEdit;
SexLabel =new QLabel(QStringLiteral("性别"));
SexComboBox =new QComboBox;
SexComboBox->addItem(QStringLiteral("女"));
SexComboBox->addItem(QStringLiteral("男"));
DepartmentLabel =new QLabel(QStringLiteral("部门:"));
DepartmentTextEdit =new QTextEdit;
AgeLabel =new QLabel(QStringLiteral("年龄"));
AgeLineEdit =new QLineEdit;
OtherLabel =new QLabel(QStringLiteral("备注:"));
OtherLabel->setFrameStyle(QFrame::Panel|QFrame::Sunken);
LeftLayout =new QGridLayout();
LeftLayout->addWidget(UserNameLabel,0,0);
LeftLayout->addWidget(UserNameLineEdit,0,1);
LeftLayout->addWidget(NameLabel,1,0);
LeftLayout->addWidget(NameLineEdit,1,1);
LeftLayout->addWidget(SexLabel,2,0);
LeftLayout->addWidget(SexComboBox,2,1);
LeftLayout->addWidget(DepartmentLabel,3,0);
LeftLayout->addWidget(DepartmentTextEdit,3,1);
LeftLayout->addWidget(AgeLabel,4,0);
LeftLayout->addWidget(AgeLineEdit,4,1);
LeftLayout->addWidget(OtherLabel,5,0,1,2);
LeftLayout->setColumnStretch(0,1);
LeftLayout->setColumnStretch(1,3);
/****右侧****/
HeadLabel =new QLabel(QStringLiteral("头像")); //右上角部分
HeadIconLabel =new QLabel;
QPixmap icon("my.png");
HeadIconLabel->setPixmap(icon);
HeadIconLabel->resize(icon.width(),icon.height());
UpdateHeadBtn =new QPushButton(QStringLiteral("更新"));
TopRightLayout =new QHBoxLayout();
TopRightLayout->setSpacing(20);
TopRightLayout->addWidget(HeadLabel);
TopRightLayout->addWidget(HeadIconLabel);
TopRightLayout->addWidget(UpdateHeadBtn);
IntroductionLabel =new QLabel(QStringLiteral("个人说明")); //右下角部分
IntroductionTextEdit =new QTextEdit;
RightLayout =new QVBoxLayout();
RightLayout->setMargin(10);
RightLayout->addLayout(TopRightLayout);
RightLayout->addWidget(IntroductionLabel);
RightLayout->addWidget(IntroductionTextEdit);
/*************************************/
QGridLayout *mainLayout =new QGridLayout(this);
mainLayout->setMargin(15);
mainLayout->setSpacing(10);
mainLayout->addLayout(LeftLayout,0,0);
mainLayout->addLayout(RightLayout,0,1);
mainLayout->setSizeConstraint(QLayout::SetFixedSize);
}
#ifndef BASEINFO_H
#define BASEINFO_H
#include
#include
#include
#include
#include
#include
#include
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;
QTextEdit *DepartmentTextEdit;
QLineEdit *AgeLineEdit;
QGridLayout *LeftLayout;
//右侧
QLabel *HeadLabel;
QLabel *HeadIconLabel;
QPushButton *UpdateHeadBtn;
QHBoxLayout *TopRightLayout;
QLabel *IntroductionLabel;
QTextEdit *IntroductionTextEdit;
QVBoxLayout *RightLayout;
};
#endif // BASEINFO_H
#include "contact.h"
Contact::Contact(QWidget *parent) : QWidget(parent)
{
EmailLabel =new QLabel(QStringLiteral("邮箱:"));
EmailLineEdit =new QLineEdit;
AddrLabel =new QLabel(QStringLiteral("联系地址:"));
AddrLineEdit =new QLineEdit;
CodeLabel =new QLabel(QStringLiteral("邮政编码:"));
CodeLineEdit =new QLineEdit;
MoviTelLabel =new QLabel(QStringLiteral("移动电话"));
MoviTelLineEdit =new QLineEdit;
MoviTelCheckBook =new QCheckBox(QStringLiteral("接受留言"));
ProTelLabel =new QLabel(QStringLiteral("办公电话"));
ProTelLineEdit =new QLineEdit;
mainLayout =new QGridLayout(this);
mainLayout->setMargin(15);
mainLayout->setSpacing(10);
mainLayout->addWidget(EmailLabel,0,0);
mainLayout->addWidget(EmailLineEdit,0,1);
mainLayout->addWidget(AddrLabel,1,0);
mainLayout->addWidget(AddrLineEdit,1,1);
mainLayout->addWidget(CodeLabel,2,0);
mainLayout->addWidget(CodeLineEdit,2,1);
mainLayout->addWidget(MoviTelLabel,3,0);
mainLayout->addWidget(MoviTelLineEdit,3,1);
mainLayout->addWidget(MoviTelCheckBook,3,2);
mainLayout->addWidget(ProTelLabel,4,0);
mainLayout->addWidget(ProTelLineEdit,4,1);
mainLayout->setSizeConstraint(QLayout::SetFixedSize);
}
#ifndef CONTACT_H
#define CONTACT_H
#include
#include
#include
#include
#include
class Contact : public QWidget
{
Q_OBJECT
public:
explicit Contact(QWidget *parent = 0);
signals:
public slots:
private:
QLabel *EmailLabel;
QLineEdit *EmailLineEdit;
QLabel *AddrLabel;
QLineEdit *AddrLineEdit;
QLabel *CodeLabel;
QLineEdit *CodeLineEdit;
QLabel *MoviTelLabel;
QLineEdit *MoviTelLineEdit;
QCheckBox *MoviTelCheckBook;
QLabel *ProTelLabel;
QLineEdit *ProTelLineEdit;
QGridLayout *mainLayout;
};
#endif // CONTACT_H
#include "content.h"
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(QStringLiteral("修改"));
CloseBtn =new QPushButton(QStringLiteral("关闭"));
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()
{
}
#ifndef CONTENT_H
#define CONTENT_H
#include
#include
#include
#include "baseinfo.h"
#include "contact.h"
#include "detail.h"
class Content : public QFrame
{
Q_OBJECT
public:
Content(QWidget *parent = nullptr);
~Content();
QStackedWidget *stack;
QPushButton *AmendBtn;
QPushButton *CloseBtn;
BaseInfo *baseInfo;
Contact *contact;
Detail *detail;
};
#endif // CONTENT_H
#include "detail.h"
Detail::Detail(QWidget *parent) : QWidget(parent)
{
NationalLabel =new QLabel(QStringLiteral("国家"));
NationalComboBox =new QComboBox;
NationalComboBox->insertItem(0,QStringLiteral("中国"));
NationalComboBox->insertItem(1,QStringLiteral("美国"));
NationalComboBox->insertItem(2,QStringLiteral("英国"));
NationalComboBox->insertItem(3,QStringLiteral("日本"));
NationalComboBox->insertItem(4,QStringLiteral("澳大利亚"));
ProvinceLabel =new QLabel(QStringLiteral("省份"));
ProvinceComboBox =new QComboBox;
ProvinceComboBox->insertItem(0,QStringLiteral("安徽省"));
ProvinceComboBox->insertItem(1,QStringLiteral("浙江省"));
ProvinceComboBox->insertItem(2,QStringLiteral("江苏省"));
ProvinceComboBox->insertItem(3,QStringLiteral("山西省"));
ProvinceComboBox->insertItem(4,QStringLiteral("广东省"));
ProvinceComboBox->insertItem(5,QStringLiteral("台湾省"));
ProvinceComboBox->insertItem(6,QStringLiteral("福建省"));
ProvinceComboBox->insertItem(7,QStringLiteral("甘肃省"));
ProvinceComboBox->insertItem(8,QStringLiteral("内蒙古省"));
ProvinceComboBox->insertItem(9,QStringLiteral("辽宁省"));
ProvinceComboBox->insertItem(10,QStringLiteral("吉林省"));
CityLabel =new QLabel(QStringLiteral("城市"));
CityLineEdit =new QLineEdit;
IntroductLabel =new QLabel(QStringLiteral("个人说明"));
IntroductTextEdit =new QTextEdit;
mainLayout =new QGridLayout(this);
mainLayout->setMargin(15);
mainLayout->setSpacing(10);
mainLayout->addWidget(NationalLabel,0,0);
mainLayout->addWidget(NationalComboBox,0,1);
mainLayout->addWidget(ProvinceLabel,1,0);
mainLayout->addWidget(ProvinceComboBox,1,1);
mainLayout->addWidget(CityLabel,2,0);
mainLayout->addWidget(CityLineEdit,2,1);
mainLayout->addWidget(IntroductLabel,3,0);
mainLayout->addWidget(IntroductTextEdit,3,1);
}
#ifndef DETAIL_H
#define DETAIL_H
#include
#include
#include
#include
#include
#include
class Detail : public QWidget
{
Q_OBJECT
public:
explicit Detail(QWidget *parent = 0);
signals:
public slots:
private:
QLabel *NationalLabel;
QComboBox *NationalComboBox;
QLabel *ProvinceLabel;
QComboBox *ProvinceComboBox;
QLabel *CityLabel;
QLineEdit *CityLineEdit;
QLabel *IntroductLabel;
QTextEdit *IntroductTextEdit;
QGridLayout *mainLayout;
};
#endif // DETAIL_H