gpt4 book ai didi

c++ - 布局在 Qt 中不起作用

转载 作者:行者123 更新时间:2023-11-30 02:04:30 25 4
gpt4 key购买 nike

我在 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);

最佳答案

您已经通过这些语句设置了对话框的布局...

 firstline = new QHBoxLayout(this);
secondline = new QHBoxLayout(this);

因此调用它们的构造函数而不指定它们的父部件。

firstline = new QHBoxLayout();
secondline = new QHBoxLayout();

这将按照您的预期显示您的布局。

关于c++ - 布局在 Qt 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10597657/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com