可以在调用Layouts控件中的insertSpacerItem( QLayout * layout, int stretch );在指定位置添加spacer, 可以调用removeItem( QLayoutItem * item )方法移除spacer
bool QBoxLayout::setStretchFactor ( QLayout * layout, int stretch )
This is an overloaded function.
Sets the stretch factor for the layout layout to stretch and returns true if layout is found in this layout (not including child layouts); otherwise returns false.
void QLayout::removeItem ( QLayoutItem * item )
Removes the layout item item from the layout. It is the caller's responsibility to delete the item.
Notice that item can be a layout (since QLayout inherits QLayoutItem).
See also removeWidget() and addItem().
//部分代码:
if(loginType == FACTORY)
{
ui->horizontalLayout->insertSpacerItem(2, ui->horizontalSpacer_3);
ui->resultRadioButton->setVisible(true);
}
else
{
ui->horizontalLayout->removeItem(ui->horizontalSpacer_3);
ui->resultRadioButton->setVisible(false);
}