用户信息窗口如果用设计师界面来做当然是非常简单了,但是为了锻炼自己的开发能力和对QT以及C++的深入理解,有必要用代码来进行操作。其实,代码比设计师界面更加灵活。看到代码多,不要害怕,其实代码中的大部分单词只需要输入开头就可以自动补全的。
新建一个项目,基于对话框,取消界面选项。
头文件如下:
#ifndef DIALOG_H
#define DIALOG_H
#include <QDialog>
#include <QLabel>
#include <QLineEdit>
#include <QComboBox>
#include <QTextEdit>
#include <QGridLayout>
#include <QPushButton>
class Dialog : public QDialog
{
Q_OBJECT
public:
Dialog(QWidget *parent = 0);
~Dialog();
private:
//左侧部分的代码
QLabel *UserNameLabel;
QLabel *NameLabel;
QLabel *SexLabel;
QLabel *DepartmentLabel;
QLabel *AgeLabel;
QLabel *OtherLabel;
QLineEdit *UserNameLineEdit;
QLineEdit *NameLineEdit;
QComboBox *SexComBox;
QLineEdit *DepartmentEdit;
QLineEdit *AgeEdit;
QGridLayout *LeftLayout;
//右侧部分的代码
QLabel *HeadLabel;
QLa