I want my QListWidget
to update with the new item as it is added, but it only updates with all of the items once the function has ended. I have tried using update()
and repaint()
, but neither work. I actually had to use repaint()
on the Widget itself just to get it to show up before the end, but none of the items do. Here is a brief view of the first item to add:
def runPW10(self):
self.PWList.setVisible(True)
self.PWList.setEnabled(True)
# This repaint() has to be here for even the List to show up
self.PWList.repaint()
....
self.PWList.addItem('Executing Change Password Tool')
# This does not help
self.PWList.repaint()
....
There is more to the function, but it is long and this should include what it needed. Please let me know if more is required.
What am I doing wrong that makes this List not update as the item is added?
Add QApplication.processEvents()
.
QCoreApplication.processEvents (QEventLoop.ProcessEventsFlags flags = QEventLoop.AllEvents)
Processes all pending events for the calling thread according to the specified flags until there are no more events to process.
You can call this function occasionally when your program is busy performing a long operation (e.g. copying a file).
Your widget originally will be shown but unresponsive. To make the application responsive, add processEvents()
calls to some whenever you add an item.
Do keep in mind that this can affect performance a lot. This lets the whole application loop execute including any queued events. Don't add this to performance sensitive loops.
Also consider that this allows your user to interact with the application, so make sure that any interactions that can happen either are not allowed, such as somebutton.enabled(False)
, or are handled gracefully, like a Cancel
button to stop a long task.
See the original C++ docs for further information, since pyqt
is a direct port.