Widget with two (or more) layouts

I need a way to customize widgets inside another widget with different layouts ...

this is something like that we have a widget divided into one layout into two parts with inscriptions, and this widget has another widget inside with a layout, as in the attached image alt text http://img713.imageshack.us/img713 /8279/multilayoutwidget.png

and we have only 4 widgets: the main widget, the shortcut one widget, the shortcut two widgets, the button widget, and for the button use one vertical and two horizontal stretches

Can any body point me to the right path? Thanks.

+4
source share
1 answer

Create a QVBoxLayout, then add two QHBoxLayouts to it. In the upper part of QHBoxLayout add shortcuts, at the bottom remove the stretch, button, stretch.

example window 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(); } 
+6
source

Source: https://habr.com/ru/post/1314623/


All Articles