Laying Out Widgets on a Form
Qt提供的的基本的Layout Manager包括:QHBoxLayout,QVBoxLayout,QGridLayout和QStackLayout。
Qt中其它能完成Layout management功能的类包括 QSplitter,QScrollArea,QMainWindow和QWorkspace。
Qt中管理child widget的layout共有三种方式:absolute positioning, manual layout和layout managers。
Absolute positioning:即由程序员通过hard-coded的形式管理child widget的位置和尺寸。
Manual Layout:child widget的位置依然由程序员通过hard-coded的方式确定,而尺寸与父窗口的大小成一定比例,而不是完全的hard-coded。这种方式通过对form的resizeEvent()进行再实现来对child widget的定位。
最重要的三个Layout Manger是QHBoxLayout,QVBoxLayout,QGridLayOut,他们都是派生自QLayout
QGridLayout的使用略微有些复杂,它工作在一个由Cell组成的二维grid上。对于QGridLayout,为其添加widget的方式如下:
layout-> addWidget(widget,row ,colum,rowSpan,columnSpan)