Refresh the mainwindow / functions called in the main loop
Hi guys,
I have this situation:
I have a QMainWindow that contains a QToolBar and a QMenuBar.
I need to disable them, do some computation and enable them again after that.
The problem is that the code:
Code:
menuBar()->setDisable(true);
myToolBar_->setDisable(true);
// do a lot of computation
menuBar()->setDisable(false);
myToolBar_->setDisable(false);
doesn't work. I guess the QMainWindow has a loop and the operations to refresh everything are called only at the end of this loop.
It should work if the mainwindow internal loop is accessed two times or if I call a function to force the update.
I have tried to call both update(), refresh() and show() (both of the mainWindow and of the other widgets) but I didn't succeed.
Do you know anything I can do about that?
I have also tried to use signals and slots but even in this way it didn't work...
Cheers
Re: Refresh the mainwindow / functions called in the main loop
May be this could help, if you call this method before doing computation, it should refresh you GUI.
http://doc.qt.io/qt-4.8/qcoreapplication.html#processEvents
Re: Refresh the mainwindow / functions called in the main loop
Be advised that blocking the event processing of the UI thread is usually not a very good idea, since you program will stop responding to any kinds of events.
No user interaction, no redrawing, no timers, no sockets, etc.
Cheers,
_
Re: Refresh the mainwindow / functions called in the main loop
Quote:
Originally Posted by
nix
Uhm ok, thank you. It's a method of the QCoreApplication so I assume I should pass a reference to it in my mainwindow, right?
Quote:
Originally Posted by
anda_skoa
Be advised that blocking the event processing of the UI thread is usually not a very good idea, since you program will stop responding to any kinds of events.
No user interaction, no redrawing, no timers, no sockets, etc.
Cheers,
_
I appreciate your suggestions and yes, maybe it would be better to process all this data in a thread but I don't need the GUI when doing the computation (they just load stuff).
For all the real computation I am using threads indeed.
Thank you again
Re: Refresh the mainwindow / functions called in the main loop
Quote:
Uhm ok, thank you. It's a method of the QCoreApplication so I assume I should pass a reference to it in my mainwindow, right?
No, it's a static method, just do QCoreApplication::processEvents();
Re: Refresh the mainwindow / functions called in the main loop
Quote:
Originally Posted by
nix
No, it's a static method, just do QCoreApplication::processEvents();
Just tried.
No difference at all.. Don't know why
Added after 40 minutes:
Just notice that if I do:
Code:
this ->update();
this ->repaint();
The toolbar greys out but not the menubar
Re: Refresh the mainwindow / functions called in the main loop
Since you don't need your UI at all, have you tried
Code:
this->setEnabled(false);
i.e. disabling the whole window?
Or instead of disabling, showing a modal progress dialog?
Cheers,
_
Re: Refresh the mainwindow / functions called in the main loop
Quote:
Originally Posted by
anda_skoa
Since you don't need your UI at all, have you tried
Code:
this->setEnabled(false);
i.e. disabling the whole window?
Or instead of disabling, showing a modal progress dialog?
Cheers,
_
Yep, I have tried both.
Disabling the whole window doesn't change anything.
Showing a modal dialog should be fine but I'd prefer a different solution.