Qt中用代码在指定位置添加spacer

来源:互联网 发布:上海模型店淘宝地址 编辑:程序博客网 时间:2024/04/28 17:17

可以在调用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);
    }

1 0
原创粉丝点击