How can I maintain an aspect ratio between two QHBoxLayouts?
For instance I want a QHBoxLayout to be one third of the entire window width and the other to be two thirds of the entire window width:
How can I achieve this? I tried messing with the size hints of the controls in them but that didn't work out
Stretch factors are used to change how much space widgets are given in proportion to one another. If we apply stretch factors to each widget, they will be laid out in proportion (but never less than their minimum size hint), e.g.
QVBoxLayout::QVBoxLayout(QWidget *parent)Constructs a new top-level vertical box with parent parent. The layout is set directly as the top-level layout for parent. There can be only one top-level layout for a widget. It is returned by QWidget::layout(). See also QWidget::setLayout().
void QSizePolicy::setHorizontalStretch(uchar stretchFactor)
Example:
QHBoxLayout* layout = new QHBoxLayout(form); QWidget* left = new QWidget(form); QSizePolicy spLeft(QSizePolicy::Preferred, QSizePolicy::Preferred); spLeft.setHorizontalStretch(1); left->setSizePolicy(spLeft); layout->addWidget(left); QWidget* right = new QWidget(form); QSizePolicy spRight(QSizePolicy::Preferred, QSizePolicy::Preferred); spRight.setHorizontalStretch(2); right->setSizePolicy(spRight); layout->addWidget(right);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With