Qt Layouts for 3 panels, all vertically expanding to fill

∥☆過路亽.° 提交于 2019-12-23 19:04:28

问题


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.


回答1:


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:



来源:https://stackoverflow.com/questions/13998090/qt-layouts-for-3-panels-all-vertically-expanding-to-fill

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!