> 文档中心 > QT 布局管理器(QHBoxLayout/QVBoxLayout/QGridLayout)

QT 布局管理器(QHBoxLayout/QVBoxLayout/QGridLayout)

1、setcontentmargins设置四周留白(相对于整个窗口的)的间隔;函数原型:void QLayout::setContentsMargins ( int left, int top, int right, int bottom )。

    layout1->setContentsMargins(1,0,1,0);

2、setMargin()在控件内部的边距设置。

3、addStretch()在布局里面添加弹簧。

4、setspacing设置控件之间的间隔;注:设置无效的可能原因有,总布局里添加控件的时候设置了比例,如图所示,去掉那个比例就可以了。

5、setStretchFactor设置布局里某几个控件之间的比例。

    mainLayout->setStretchFactor(m_listWidget,1);    mainLayout->setStretchFactor(m_stackWidget,9);

6、QGridLayout::addWidget()的调用遵循如下的语法形式

    layyout->addWidget(widget,fromRow,fromColumn,rowSpan,columnSpan);

widget是要插入到布局中的字窗口部件,(fromRow,frowColum)是由该窗口部件所占的左上角单元格,rowSpan是该窗口部件要占用的行数,而columnSpan是该窗口部件要占用的列数,如果省略了这些参数,则参数rowSpan和将会取默认值1。