0

私はqtを初めて使用し、それを調査しています。基本的に、親レイアウトに3つの子レイアウトを追加しています。しかし、3番目のレイアウトを追加した後、最初のレイアウトが消えます。これは私のコードです:

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