[SOLVED] How to set Multiple QGroupBox alignment in QVBoxLayout



  • This is a seemingly basic issue. But I am having difficultly getting exactly what I want. I have a QVBoxLayout that I want to stack multiple QGroupBox widgets into. I want them to align from top to bottom and stay connected together. This is what happens by default:
    !http://i.imgur.com/JZbYaRC.png()!

    I have tried several alignment settings. This will work, but is this the right way?

    @ ui->NodeView->addWidget(m_nodeTransform);
    ui->NodeView->addWidget(m_nodeCommon);

    ui->NodeView->setAlignment(m_nodeCommon, Qt::AlignTop);@


  • Hi,
    The empty space needs to be filled by something. Use a Vertical spacer below the last QGroupbox and your fine. OTherwise the layout will try to fill the available space with the widgets it has (the two groupboxes)



  • That worked. Thank you!

    Here's a snippet of code that did it.

    @QSpacerItem* spacer = new QSpacerItem(300,1000, QSizePolicy::Expanding, QSizePolicy::Expanding);
    spacer->setAlignment(Qt::AlignVCenter);

    ui->NodeView->addWidget(m_nodeTransform);
    ui->NodeView->addWidget(m_nodeCommon);
    ui->NodeView->addWidget(m_nodeDrawable);
    ui->NodeView->addItem(spacer);@



  • Oke, glad it helped!
    Here is some docs for you to solve other issues with layouts:
    "LayoutManagement":http://qt-project.org/doc/qt-5/layout.html
    Also, the use of addItem is not wrong, but it might be better to use this:
    @
    void QBoxLayout::addSpacerItem(QSpacerItem * spacerItem)
    @
    This is more appropriate.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.