通过函数调用缩小 QDialog
我有一个由中央应用程序创建和管理的对话。对话框在运行时生成小部件,并具有一个成员函数将对话框恢复为其默认排列,即顶部的按钮框和底部的单个小部件。当对话隐藏时调用此恢复函数。我可以从对话中获取额外的小部件,但我无法让对话本身缩小到原始大小。这是我正在使用的代码,名称已更改为通用名称。
void Dialogue::restore()
{
const short RESTORE_WIDTH = 800;
const short RESTORE_HEIGHT = 200;
QRect newGeometry(frameGeometry());
// Remove all old origins
foreach(RuntimeWidget* child, findChildren< RuntimeWidget* >())
child->deleteLater();
// Restore widget to default state
newGeometry.setWidth(RESTORE_WIDTH);
newGeometry.setHeight(RESTORE_HEIGHT);
setGeometry(newGeometry);
updateGeometry();
addRuntimeWidget();
}
void Dialogue::addRuntimeWidget()
{
RuntimeWidget* pWidget(new RuntimeWidget());
vbxlytDialogue->addWidget(pWidget);
adjustSize();
adjustPosition(this);
pWidget->setFocus(Qt::OtherFocusReason);
}
I have a dialogue that is created and managed by the central application. The dialogue generates widgets at runtime and has a member function to restore the dialogue to its default arrangement, I.e. button box at the top and a single widget on the bottom. This restore function is called while the dialogue is hidden. I can get the extra widgets out of the dialogue, but I cannot get the dialogue itself to shrink to it's original size. Here is the code I'm using, names have been changed to be generic.
void Dialogue::restore()
{
const short RESTORE_WIDTH = 800;
const short RESTORE_HEIGHT = 200;
QRect newGeometry(frameGeometry());
// Remove all old origins
foreach(RuntimeWidget* child, findChildren< RuntimeWidget* >())
child->deleteLater();
// Restore widget to default state
newGeometry.setWidth(RESTORE_WIDTH);
newGeometry.setHeight(RESTORE_HEIGHT);
setGeometry(newGeometry);
updateGeometry();
addRuntimeWidget();
}
void Dialogue::addRuntimeWidget()
{
RuntimeWidget* pWidget(new RuntimeWidget());
vbxlytDialogue->addWidget(pWidget);
adjustSize();
adjustPosition(this);
pWidget->setFocus(Qt::OtherFocusReason);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我猜您在此处使用
deleteLater
存在问题。只有当您返回到主事件循环时,子窗口小部件才会被删除,并且只有在restore()
完成之后(即在您调用 <代码>调整大小)。在调用
deleteLater()
之前,您是否尝试过从子部件所在的布局中删除它们?(或者类似的东西 - 我只是猜测 vbxlytDialogue 的类型。)
I'm guessing there's a problem with your use of
deleteLater
here. The child widgets will only get deleted once you go back to the main event loop, and that will only happen afterrestore()
is finished (i.e. after you've calledadjustSize
).Have you tried removing the child widgets from whatever layout they're in before calling
deleteLater()
?(Or something to that effect - I'm just guessing about the type of
vbxlytDialogue
.)