Qt Layouts for 3 panels, all vertically expanding to fill

c++, pyqt, pyside, qt

Solution

You need a

QHBoxLayout

You just have to set a fixed width for your fixed widgets (in the left).

Here is a complete working example in C++:

#include <QApplication>
#include <QtGui>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QFrame* w1 = new QFrame;
    w1->setFixedWidth(100);
    w1->setStyleSheet("background-color: red");

    QFrame* w2 = new QFrame;
    w2->setFixedWidth(100);
    w2->setStyleSheet("background-color: blue");

    QFrame* w3 = new QFrame;
    w3->setStyleSheet("background-color: green");
    w3->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);

    QHBoxLayout* layout = new QHBoxLayout;

    layout->addWidget(w1);
    layout->addWidget(w2);
    layout->addWidget(w3);

    QWidget* app = new QWidget;
    app->setLayout(layout);
    app->show();
    return a.exec();
}

And the screenshot:

Problem

I am rather new to desktop GUI development. I am trying to get a frame with 3 parallel vertical panels, all expanding vertically to fill the window. I want the first two panels not to be flexible but to have a fixed size. Ex: ``` Fixed W. |========| ############################ # # # # ^ #Fix.#Fix.# # | #|--|#|--|# <--Flexible--> # Flexible vertically all 3 panels. # # # # | # # # # v ############################ ``` How can I obtain this layout? I am tried Grid, Vertical, Horizontal but I think I got it all spaghetti-like and confused. Thank you.

Original source