I have two QDialogs stacked on top of each other, with some data is shared between them shown in a QWidget in each dialog's layout (a widget showing a count graphically).
In the QDialog currently shown, the user can change that data. This change gets propagated to both widgets, and the correct count is displayed in the current QDialog. However, when the user closes that QDialog, and the one underneath becomes visible, the QWidget showing the count shows the old value for a split second before it then updates to the correct value.
I know that the QWidget underneath has the correct value before the other QDialog is shown, but I can't seem to get the Dialog to update before it's visible. I tried this while it was still hidden:
hiddenDialog->layout()->activate()
hiddenDialog->layout()->update()
But it still fails to actually update until after dialog is shown. My problem seems sort-of related to Qt: How to force a hidden widget to calculate its layout?, except I want to then show the QDialog after setting Qt::WA_DontShowOnScreen on. After turning on Qt::WA_DontShowOnScreen and updating the dialog, I tried setting:
dialog->setAttribute(Qt::WA_DontShowOnScreen, false);
dialog->show()
But the Dialog remains not shown on screen. Is there any way to make it visible again? Or is there some way to have the dialog and widgets update when they are hidden by the other dialog?
Here's some more details as requested: There are two classes, Dialog1 and Dialog2, each extending the same base class, BaseDialog, which extends the QDialog class.
BaseDialog has a slot that gets called whenever the GlobalCount is changed. This slot updates a countWidget which draws a picture of the count.
void BaseDialog::updateCountWidget()
{
_countWidget->updateCount(globalCount);
_countWidget->update();
}
Dialog1 has a slot (connected from a QPushButton click()) that creates and shows a Dialog2:
void Dialog1::showDialog2()
{
Dialog2* dialogTwo = new Dialog2();
dialog2->show();
}
Dialog2 has two slots (connected to QPushButton signals), one subtract from the global count, the other closes the dialog. When the global count is subtracted, it emits a signal connected to the updateCountWidget() slot of both the Dialog1 and Dialog2.
void Dialog2::subtractCount()
{
GlobalCount.subtractOne();
}
void Dialog2::userClosed()
{
accept();
}
When I click the subtract button, I can see the _countWidget of Dialog2 update correctly. However, when I close Dialog2, and can once again see Dialog1, the _countWidget of Dialog1 shows the original count value for a split-second, then updates to the new value.
My goal is to prevent this momentary update, as it looks really funky to the user. This has gotten obscenely long, but I appreciate any insights!