具有两个(或更多)布局的小部件

vin*_*itu 4 layout qt widget

我需要在不同布局的其他窗口小部件中设置窗口小部件的方法...

它就像我们有小部件由一个布局分成两个部分带标签,这个小部件有其他小部件内部布局,如附加图像alt文本http://img713.imageshack.us/img713/8279/multilayoutwidget.png

我们只有4个小部件:主要小部件,标签一个小部件,标签两个小部件,按钮小部件,按钮使用一个垂直和两个水平拉伸

有些身体可以指出我正确的做法吗?谢谢.

Sig*_*erm 7

创建QVBoxLayout,然后向其添加两个QHBoxLayouts.在顶部QHBoxLayout添加标签,在底部添加拉伸,按钮,拉伸.

窗口示例http://img196.imageshack.us/img196/545/86911694.png

#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();
}
Run Code Online (Sandbox Code Playgroud)