QT网格布局#includeQApplication#includeQLabel#includeQLineEdit#includeQGridLayoutint main(in
QT网格布局
#include<QApplication>
#include<QLabel>
#include<QLineEdit>
#include<QGridLayout>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
//创建一个窗口,并设置标题
QWidget *window = new QWidget;
window->setWindowTitle("my app");
//创建一个标签和行编辑器
QLabel *label_1 = new QLabel("Name :");
QLineEdit *name_1 = new QLineEdit;
//创建一个标签和行编辑器
QLabel *label_2 = new QLabel("Name :");
QLineEdit *name_2 = new QLineEdit;
//创建一个标签和行编辑器
QLabel *label_3 = new QLabel("Name :");
QLineEdit *name_3 = new QLineEdit;
//创建一个网格布局器
QGridLayout *layout = new QGridLayout;
//在0行0列添加label_1
layout->addWidget(label_1, 0,0);
//在0行1列添加name_1
layout->addWidget(name_1, 0,1 );
//分别在第2行0列和1列添加组件
layout->addWidget(label_2, 1,0);
layout->addWidget(name_2, 1,1 );
//分别在第3行0列和1列添加组件
layout->addWidget(label_3, 2,0);
layout->addWidget(name_3, 2,1 );
window->setLayout(layout);
window->show();
return a.exec();
}