标签:qt
先定义头文件:address.h
#ifndef ADDRESSBOOK_H #define ADDRESSBOOK_H #include <QWidget> QT_BEGIN_NAMESPACE class QLabel; class QLineEdit; class QTextEdit; QT_END_NAMESPACE //! [class definition] class AddressBook : public QWidget { Q_OBJECT public: AddressBook(QWidget *parent = 0); private: QLineEdit *nameLine; QTextEdit *addressText; }; //! [class definition] #endif
#include <QtWidgets> #include "addressbook.h" //! [constructor and input fields] AddressBook::AddressBook(QWidget *parent) : QWidget(parent) { QLabel *nameLabel = new QLabel(tr("Name:")); nameLine = new QLineEdit; QLabel *addressLabel = new QLabel(tr("Address:")); addressText = new QTextEdit; //! [constructor and input fields] //! [layout] 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); //! [layout] //![setting the layout] setLayout(mainLayout); setWindowTitle(tr("Simple Address Book")); } //! [setting the layout]
#include <QtWidgets> #include "addressbook.h" //! [main function] int main(int argc, char *argv[]) { QApplication app(argc, argv); AddressBook addressBook; addressBook.show(); return app.exec(); } //! [main function]
现在地址薄只能显示名字、地址的标签和编辑栏,还没有添加功能,需要进一步
修改。
标签:qt
原文地址:http://blog.csdn.net/wangjiaweiwei/article/details/44827891