Issue
I have a list of dictionaries like dict = {'text': 'abcd', 'delay': 1.234}
. I have a loop which for each dictionary of the list wait for the 'delay'
and after do something with the 'text'
:
for element in myList:
time.sleep(element['delay'])
self.ui.textEdit.append(element['text'])
print element['text']
myFunction(element['text'])
The sleep
, print
and myFunction
work as they should work. But the textEdit never change and in title of my window I have: 'Not responding'. How can I avoid this problem ?
Solution
Your code is blocking Qt's main event loop. The GUI update events are queued and won't be processed until the event loop is allowed to run again.
A possible workaround would be to call QtCore.QCoreApplication.processEvents()
after you append the text to textEdit
to force the event loop to run and process events in the queue.
A more general solution would be to move your code into a worker thread so that the main thread is free to continue processing GUI events. Take a look at the answers by myself and Shadow9043 in this question for further information. The question itself is somewhat different to yours but the solution is similar (note that coded example is written in PyQt so may be a little different to PySide).
Answered By - user3419537
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.