QT::控件类4

 

QHBoxLayout横向布局
//向布局中添加控件 
hboxLayout->addWidget(button1); 
hboxLayout->addWidget(button2); 
hboxLayout->addWidget(button3);
//间隔 
hboxLayout->setSpacing(60);
//实例QWidget 
widget = new QWidget(); 
//绑定布局 
widget->setLayout(hboxLayout); 
//绑定界面 
this->setCentralWidget(widget);

 

QGridLayout网格布局
//创建纵向布局 
gridLayout = new QGridLayout();
button1 = new QPushButton("按钮1"); 
button2 = new QPushButton("按钮2"); 
button3 = new QPushButton("按钮3");
//向布局中添加控件 
gridLayout->addWidget(button1,0,0,1,1); 
gridLayout->addWidget(button2,0,1,1,1); 
gridLayout->addWidget(button3,1,0,1,1);
//实例QWidget 
widget = new QWidget();
//绑定布局 
widget->setLayout(gridLayout); 
//绑定界面 
this->setCentralWidget(widget);

 



 

上一篇:Python-GUI编程-PyQt5


下一篇:PyQt5 第二章 窗口布局管理(一)