开发者

widget with two(or more) layout

I need the way to setup widgets inside other widget with different layouts...

it is something like we have widget divided by one layout into two parts with labels, and this widget have other widget inside with layout like on attached image

widget with two(or more) layout

and we have only 4 widgets: main widget, label one widget, label two widget, button widget, and for button use one vertical and two hori开发者_Python百科zontal stretch

Can some body point me to right way do it? Thanks.


Create QVBoxLayout, then add two QHBoxLayouts to it. In top QHBoxLayout add labels, in bottom one add stretch, button, stretch.

widget with two(or more) layout

#include <QString>
#include <QApplication>
#include <QWidget>
#include <QPushButton>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLabel>
#include <QLocale>

int main(int argc, char** argv){
    QApplication app(argc, argv);

    QWidget widget;

    QVBoxLayout* vLayout = new QVBoxLayout(&widget);
    QHBoxLayout* topLayout = new QHBoxLayout();
    QHBoxLayout* bottomLayout = new QHBoxLayout();
    QLabel* label1 = new QLabel(QObject::tr("Label1"));
    QLabel* label2 = new QLabel(QObject::tr("Label2"));
    label1->setAlignment(Qt::AlignCenter);
    label2->setAlignment(Qt::AlignCenter);
    QPushButton* btn1 = new QPushButton(QObject::tr("The Button!!!!"));
    topLayout->addWidget(label1);
    topLayout->addWidget(label2);
    bottomLayout->addStretch();
    bottomLayout->addWidget(btn1);
    bottomLayout->addStretch();
    vLayout->addLayout(topLayout);
    vLayout->addLayout(bottomLayout);

    widget.show();

    return app.exec();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜