Atul Kulkarni
Atul Kulkarni

Reputation: 135

Qt QVBoxLayout: How to divide the layout in fixed height Boxes?

I want to divide my window in the following manner

    Build a vertical layout
    -------------------------
    |                       |
    -------------------------
    |                       |
    |                       |
    |                       |
    |                       |
    |                       |
    |                       |
    -------------------------

using QVBoxLayout. I want to maintain this ratio at all times. I will disabling re-sizing the window. Right now I have the following code.

QVBoxLayout baseLayout = new QVBoxLayout(this);
QLabel *widget = new QLabel(NULL);
widget->setStyleSheet("background-color: rgb(0, 39, 118)");
widget->setGeometry(0,0,400, 30);
widget->setPixmap(QPixmap("Logo-Large.gif"));
baseLayout->addWidget(widget);

...

This divides the window in equal parts. I can't use the form designer as I am building this UI dynamically.

Is there any property on QVBoxLayout that I can use to achieve this? Or Using this QVBoxLayout is simply wrong, if so please suggest an alternative.

Thanks and Regards, Atul.

Upvotes: 3

Views: 2106

Answers (1)

Johannes Schaub - litb
Johannes Schaub - litb

Reputation: 507313

To make a QVBoxLayout keep a fixed ratio between two elememts, give them stretch parameters in addWidget. A stretch parameter of N that is x times another stretch parameter Y will make the corresponding widget have a height x times higher than the other widget.

Upvotes: 3

Related Questions