【发布时间】:2012-05-22 18:47:39
【问题描述】:
我在 Qt 中遇到了布局问题。我正在尝试使用 2 个水平布局和一个垂直主布局来编译此代码。每个水平布局都有 3 个按钮,并且两个水平布局都包含在垂直布局中。但是在我编译完这段代码后,我只能看到一个只有“退出”按钮的小窗口。
firstline = new QHBoxLayout(this);
secondline = new QHBoxLayout(this);
layout = new QVBoxLayout(this);
eat = new QPushButton("Eat", this);
drink = new QPushButton("Drink", this);
smoke = new QPushButton("Smoke", this);
save = new QPushButton("Save", this);
load = new QPushButton("Load", this);
exit = new QPushButton("Exit", this);
firstline->addWidget(eat);
firstline->addWidget(drink);
firstline->addWidget(smoke);
secondline->addWidget(save);
secondline->addWidget(load);
secondline->addWidget(exit);
layout->addLayout(firstline);
layout->addLayout(secondline);
setLayout(layout);
【问题讨论】:
-
记住
QGridLayout在这种情况下可能更容易使用。 -
我知道,但布局不起作用。我使用 QGridLayout 重写了这段代码,结果是一样的。问题一定是我的,或者我在代码中遗漏了一些东西。