0

QDialog在设计器中创建了一个带有QFrametestFrame 的设计器,我已经添加了一个QHBoxLayout,并且在创建并显示整个东西之后的某个时刻,我试图以编程方式创建一个新的小部件,并将其QFrame作为父级。无论我尝试什么新小部件都不会显示:

init() 方法结束:

QBoxLayout *testFrameLayout = new QHBoxLayout(this->testFrame); //QT3 docs use QBoxLayout pointer when creating QHBoxLayout

在事件期间(例如,按下了单独的按钮)

testButton = new QPushButton(this->testFrame);
testButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed, false);
testButton->setMaximumWidth(50);
testButton->setMaximumHeight(50);
testButton->setMinimumWidth(50);
testButton->setMinimumHeight(50);

testFrameLayout->addWidget(testButton);

我通过不同的小部件、容器类(例如QGrid,我不必管理任何布局的东西)、调用 update()/repaint()(在 testFrame、testButton、对话框本身)等,无论我尝试什么它都可以得到这种行为在 init() 中完成时,但如果在显示对话框后完成,则不会。我一定错过了一些东西,所以任何帮助将不胜感激!

注意:我正在做一个使用 Qt 3 的非常大的项目,因此解决方案必须与此版本兼容。

4

2 回答 2

0

打电话

testButton->show();

最后解决了这个问题。由于在实际按钮上没有 show() 的框架上使用 adjustSize() 会使框架消失,我认为可能小部件是隐藏的,直到像这样添加时明确显示。

于 2013-12-17T16:24:58.850 回答
0

这是我的 Qt3 应用程序中对话框中的一些工作代码:

QVBoxLayout *vb = new QVBoxLayout(this, 5, 5);
// ...
QHBoxLayout *askline = new QHBoxLayout(vb, 10);
QPushButton *ok      = new QPushButton(tr("OK"), this);
QPushButton *cancel  = new QPushButton(tr("Cancel"), this);
askline->addWidget(ok);
askline->addWidget(cancel);
adjustSize();
// ...

我认为您的问题是布局没有为您分配任何空间QPushButton并且adjustSize()是需要的。

于 2013-12-17T13:46:57.063 回答