widget with two(or more) layout
12,322
Create QVBoxLayout, then add two QHBoxLayouts to it. In top QHBoxLayout add labels, in bottom one add stretch, button, stretch.
#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();
}
Author by
vinnitu
Updated on June 04, 2022Comments
-
vinnitu almost 2 years
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
and we have only 4 widgets: main widget, label one widget, label two widget, button widget, and for button use one vertical and two horizontal stretch
Can some body point me to right way do it? Thanks.