PyQt之QHBoxLayout、QVBoxLayout 与QGridLayout

一. QHBoxLayout
先来看官方对QHBoxLayout 是怎样介绍的,原文如下:
The QHBoxLayout class lines up widgets horizontally.
QHBoxLayout 类将各部件水平排列。
This class is used to construct horizontal box layout objects. See QBoxLayout for details.
这个类用来构建水平框布局对象,更详细的信息请看QBoxLayout。
The simplest use of the class is like this:
这个类最简单的用法像下面这样:

     QWidget *window = new QWidget;
     QPushButton *button1 = new QPushButton("One");
     QPushButton *button2 = new QPushButton("Two");
     QPushButton *button3 = new QPushButton("Three");
     QPushButton *button4 = new QPushButton("Four");
     QPushButton *button5 = new QPushButton("Five");

     QHBoxLayout *layout = new QHBoxLayout;
     layout->addWidget(button1);
     layout->addWidget(button2);
     layout->addWidget(button3);
     layout->addWidget(button4);
     layout->addWidget(button5);

     window->setLayout(layout);
     window->show();

First, we create the widgets we want in the layout. Then, we create the QHBoxLayout object and add the widgets into the layout. Finally, we call QWidget.setLayout() to install the QHBoxLayout object onto the widget. At that point, the widgets in the layout are reparented to have window as their parent.
首先,在这个布局里面我们创建了我们想要的widget(部件)。 然后,我们创建了QHBoxLayout类的一个对象并且把我们刚才创建的widget(部件)加入到了这个对象里。 最后,我们调用了QWidget.setLayout()方法将QHBoxLayout对象“安装”到了widget里。在那一点上,布局里的各个widget(部件)让window(窗口)成为了他们的父部件(这句真不好翻译,翻得不对请高手赐教^_^)。
上面的描述是官方介绍的,其实说白了就是,先定义一个QHBoxLayout对象(new出来),然后调用该对象的addWidget方法添加部件(按钮、文本等等),
这些刚刚添加进去的部件们在布局管理器中是水平排列的。这个时候这些部件是不能显示的,我们还要将他们与一个对象(QWidget对象、
QMainWindow对象或QDialog对象)进行“绑定”(原文里是install),然后调用该对象的sho

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值