2012年(1008)
分类:
2012-08-01 11:07:55
原文地址:入门级实例:设计一个用户界面 作者:luozhiyong131
//main.cpp
/*
* 入门级实例:设计一个用户界面
* 使用图形用户界面开发一个地址簿应用程序
* Lzy 2011-8-24
*/
#include
#include "addressbook.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
AddressBook *addressBook = new AddressBook;
addressBook->show();
return app.exec();
}
//addressbook.h
#ifndef ADDRESSBOOK_H
#define ADDRESSBOOK_H
#include
#include
#include
class AddressBook : public QWidget
{
Q_OBJECT
public:
AddressBook(QWidget *parent = 0);
private:
QLineEdit *nameLine;
QTextEdit *addressText;
};
#endif // ADDRESSBOOK_H
//addressbook.cpp
#include "addressbook.h"
#include
#include
AddressBook::AddressBook(QWidget *parent) : QWidget(parent)
{
QLabel *nameLabel = new QLabel(tr("Name:"));
nameLine = new QLineEdit;
QLabel *addressLabel = new QLabel(tr("Address:"));
addressText = new QTextEdit;
/*网络布局*/
QGridLayout *mainLayout = new QGridLayout;
mainLayout->addWidget(nameLabel,0,0);
mainLayout->addWidget(nameLine,0,1);
mainLayout->addWidget(addressLabel,1,0,Qt::AlignTop); //当前布局的上面
mainLayout->addWidget(addressText,1,1);
setLayout(mainLayout);
setWindowTitle(tr("Simple Address book"));
}