续上一文
- 在"detail.cpp"文件中添加如下代码:
```cpp
Detail::Detail(QWidget *parent) : QWidget(parent)
{
NationalLabel = new QLabel(tr("国家/地址:"));
NationalComboBox = new QComboBox;
NationalComboBox->insertItem(0, tr("中国"));
NationalComboBox->insertItem(1, tr("美国"));
NationalComboBox->insertItem(2, tr("英国"));
ProvinceLabel = new QLabel(tr("省份:"));
ProvinceComboBox = new QComboBox;
ProvinceComboBox->insertItem (0, tr("江苏省"));
ProvinceComboBox->insertItem(1, tr("山东省"));
ProvinceComboBox->insertItem(2, tr("浙江省"));
CityLabel = new QLabel(tr("城市:"));
CityLineEdit = new QLineEdit;
IntroductLabel = new QLabel(tr("个人说明:"));
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);
}
```
- 编写主函数在"main.cpp"文件中:
```cpp
#include "content.h"
#include <QApplication>
#include <QTextCodec>
#include <QSplitter>
#include <QListWidget>
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, QObject::tr("基本信息"));
list->insertItem(1, QObject::tr("联系方式"));
list->insertItem(2, QObject::tr("详细资料"));
Content *content = new Content(splitterMain);
QObject::connect(list, SIGNAL(currentRowChanged(int)), content->stack, SLOT(setCurrentIndex(int)));
splitterMain->setWindowTitle(QObject::tr("修改用户资料"));
splitterMain->setMinimumSize(splitterMain->minimumSize());
splitterMain->setMaximumSize(splitterMain->maximumSize());
splitterMain->show();
return a.exec();
}
```
可选择不同的布局方案,根据具体情况使用最方便、合理的布局方式。通常,QGridLayout能完成QHBoxLayout与QVBoxLayout的功能,但对于简单的水平或竖直排列,后两者更方便,而QGridLayout适合方正整齐的界面布局。