2

I am adding some user feedback to a plugin. I have followed the pyqgis developer cookbook to create a message as below.

self.iface.messageBar().clearWidgets()
messagelinktext = 'something is happening'
self.iface.messageBar().pushMessage("", messagelinktext, Qgis.Warning, duration=10)

This works fine but I would like to show a sequence of messages and at the moment the various steps take a while to execute but only the last message is displayed once the operations have been completed.

1 Answer 1

2

You could use QTimer.singleShot to create a one-time timer that triggers the pushMessage-call after a specified time (in ms):

from qgis.utils import iface
from PyQt5.QtCore import QTimer

iface.messageBar().pushMessage("Info", "first message", duration=5)
QTimer.singleShot(5100, lambda: iface.messageBar().pushMessage("Info", "second message"))
3
  • 1
    It seems all I need to do is add in "self.iface.mainWindow().repaint()" between my messages so the intermediate ones display
    – Sethinacan
    Commented Nov 21 at 11:11
  • 1
    You might also consider running your sequence of steps in a QgsTask to avoid blocking the UI while they are running.
    – couteau
    Commented Nov 21 at 22:40
  • @couteau , I found some documentation regarding that but didn't get very far, re-painting the mainWindow seems to work fine for now but I can see running as tasks in the background would be better.
    – Sethinacan
    Commented Nov 25 at 14:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.