C++ Qt 佈局
阿新 • • 發佈:2018-12-17
#include "widget.h" #include <QtGui> #include <QtCore> Widget::Widget(QWidget *parent) :QWidget(parent) { QLabel *l1=new QLabel(tr("姓名")); QLabel *l2=new QLabel(tr("姓別")); QLabel *l3=new QLabel(tr("年齡")); QLabel *l4=new QLabel(tr("職工號")); QLabel *l5=new QLabel(tr("說明====>:")); QLineEdit *l11=new QLineEdit(tr("Tom")); QLineEdit *l12=new QLineEdit(tr("man")); QLineEdit *l13=new QLineEdit(tr("21")); QLineEdit *l14=new QLineEdit(tr("15159257473")); QTextEdit *text=new QTextEdit(tr("a simple test!")); QPushButton *btn1=new QPushButton(tr("提交")); QPushButton *btn2=new QPushButton(tr("儲存")); QPushButton *btn3=new QPushButton(tr("退出")); QVBoxLayout *lay_v = new QVBoxLayout(this); QHBoxLayout *lay_h1 = new QHBoxLayout(); QHBoxLayout *lay_h2 = new QHBoxLayout(); QHBoxLayout *lay_h3 = new QHBoxLayout(); QHBoxLayout *lay_h4 = new QHBoxLayout(); QHBoxLayout *lay_h5 = new QHBoxLayout(); QHBoxLayout *lay_h6 = new QHBoxLayout(); QHBoxLayout *lay_h7 = new QHBoxLayout(); lay_h1->addWidget(l1); lay_h1->addWidget(l11); lay_h2->addWidget(l2); lay_h2->addWidget(l12); lay_h3->addWidget(l3); lay_h3->addWidget(l13); lay_h4->addWidget(l4); lay_h4->addWidget(l14); lay_h5->addWidget(l5); lay_h6->addWidget(text); lay_h7->addSpacing(200); lay_h7->addWidget(btn1); lay_h7->addWidget(btn2); lay_h7->addWidget(btn3); lay_v->addLayout(lay_h1); lay_v->addLayout(lay_h2); lay_v->addLayout(lay_h3); lay_v->addLayout(lay_h4); lay_v->addLayout(lay_h5); lay_v->addLayout(lay_h6); lay_v->addLayout(lay_h7); connect(btn3, SIGNAL(clicked()), this, SLOT(close())); } Widget::~Widget() { }