Qt:Child Layouts not getting added Properly

519 Views Asked by At

I'm new to qt and exploring it .Basically Im adding three child layouts to a Parent layout.But after having added the third layout,my first layout disappears. This is my code:

MainWindow::MainWindow(QWidget *parent) :
QWidget(parent),
ui(new Ui::MainWindow)
{

this->setGeometry(500,650,1000,1000);

QVBoxLayout *parentLayout = new QVBoxLayout(this);

QVBoxLayout *l1 = new QVBoxLayout();
QWidget *lw1 = new QWidget;
lw1->setMaximumHeight(50);
lw1->setStyleSheet("background-color:brown");
l1->addWidget(lw1);

QHBoxLayout *l2 = new QHBoxLayout;

QLabel *label = new QLabel("Industry");
label->setStyleSheet("color:white");
label->setMaximumWidth(300);
label->setAlignment(Qt::AlignTop);
l2->addWidget(label);


QComboBox *cb = new QComboBox;
cb->addItem("Movie");
cb->setStyleSheet("background-color:white");
cb->setMaximumHeight(50);
l2->addWidget(cb);

l2->setAlignment(Qt::AlignTop);

parentLayout->addLayout(l1);

parentLayout->addLayout(l2);

//If I run till here I see the added two child layouts.

QWidget *w3 = new QWidget;
w3->setStyleSheet("background-color:white");

QVBoxLayout *l3 = new QVBoxLayout();
l3->addWidget(w3);
l3->setAlignment(Qt::AlignTop);


//parentLayout->addLayout(l3);
//If I uncomment the above line then I see only layouts l2 and l3 from the top and not l1

}

Basically what I need is a Layout which in turn containing multiple subLayouts of varied sizes.Could someone highlight me where am I doing mistake.Any help will be really useful.

0

There are 0 best solutions below