Fixing a Frozen Status Bar in PyQt4
In one of my recent apps a long-running web request blocked the UI, so I wanted a status bar message to show what the background task was doing.
Multithreading approach
I had solved a similar problem before with a worker thread:
1 | class SetLabelText(QThread): |
And inside the time-consuming section:
1 | self.m1 = SetLabelText(self.status_label, u"Reminder") |
A simpler option
Threads work, but when you update the status message multiple times in the same method you end up handling extra complexity. I found a simpler approach: update the label directly and immediately flush the event loop:
1 | self.status_label.setText(u"Loading configuration… please wait…") |
Reference: