Qt控件之布局管理-QGridLayout网格布局控件的使用总结
在Qt开发中,界面布局是非常重要的一环。Qt提供了多种布局管理器,其中最常用的是网格布局管理器(QGridLayout)。QGridLayout将控件放置于一个二维表格中,可以自由地设置每个控件所占用的行数和列数,从而实现各种各样的布局效果。
下面我们来看一个实例:
#include <QtWidgets>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget* window = new QWidget;
QGridLayout* layout = new QGridLayout(window);
QLabel* label1 = new QLabel("Label 1");
QLabel* label2 = new QLabel("Label 2");
QLabel* label3 = new QLabel("Label 3");
QLineEdit* lineEdit1 = new QLineEdit;
QLineEdit* lineEdit2 = new QLineEdit;
QLineEdit* lineEdit3 = new QLineEdit;
QPushButton* button1 = new QPushButton("Button 1");
QPushButton* button2 = new QPushButton("Button 2");
layout-&g