一. 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