Solved Strange: QProgressDialog keeps appearing when clicking on menus on the main window
-
I have a QProgressDialog declared in the MainWindow class. It is setup in the MainWindow constructor as follows:
dialog = new QProgressDialog(tr("Processing") + "...", tr("Cancel"), 0, 4, this); dialog->setWindowModality(Qt::WindowModal);
It is strange but when I click on menu (headings) on the main window, the dialogue appears all by it self without any code calling it or without clicking on any menu item.
-
@Guerrian
then there must be more code which causing this behavior ;) -
Hi
Actually i could reproduce it
with only that 2 lines of code
I simply run program and wait a moment. ( 5-8 secs) then it pops :)
(also in a new clean default GUI project with no menus ) -
I need this to be in the scope of the main window. How do I control this dialogue and prevent it from appearing randomly?
Update
I tried adding "reset", seems to have solved the problem:dialog = new QProgressDialog(tr("Processing") + "...", tr("Cancel"), 0, 4, this); dialog->setWindowModality(Qt::WindowModal); dialog->reset();
-
Hi
try without
dialog->setWindowModality(Qt::WindowModal);
and see if that makes a difference. -
@mrjj
But when I do want it to show, I want the window to be modal! -
@Guerrian
Yeah, u can set same place you call show()
It was just for test.Its a bit odd it pops up.Never mind. :)
Reading the docs , it clear states why it pops.
its due to setMinimumDuration
http://doc.qt.io/qt-5/qprogressdialog.html#minimumDuration-prop -
@mrjj
Without this line it still pops up:dialog->setWindowModality(Qt::WindowModal);
I found that it does not pop up if I use reset at the start:
dialog->setWindowModality(Qt::WindowModal); dialog->reset();
...use this if the process is cancelled:
dialog->close();
...and do nothing if the process finishes ie. the progress bar reaches maximum, because it auto resets in that case.
-
@Guerrian
Yes ?
I posted why :)
the docs have the info. -
@mrjj
OK, but does it explain about reset? It says about showing "any progress", this seems to apply when there is zero progress. Whereas reset can actually hide the dialogue. -
@Guerrian
Yes it says that
void QProgressDialog::reset()
Resets the progress dialog. The progress dialog becomes hidden if autoClose() is true.