0

我是 qt 的新手并正在探索它。基本上我在父布局中添加了三个子布局。但是在添加了第三个布局之后,我的第一个布局消失了。这是我的代码:

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

}

基本上我需要的是一个布局,它又包含多个不同大小的子布局。有人可以突出显示我在哪里做错了。任何帮助都会非常有用。

4

0 回答 0