Shrinking QDialog With Function Call
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);
}
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 after restore()
is finished (i.e. after you've called adjustSize
).
Have you tried removing the child widgets from whatever layout they're in before calling deleteLater()
?
foreach(RuntimeWidget* child, findChildren< RuntimeWidget* >()) {
vbxlytDialogue->removeWidget(child);
child->deleteLater();
}
(Or something to that effect - I'm just guessing about the type of vbxlytDialogue
.)
精彩评论