3

The default for messages generated with self.iface.messageBar().pushCritical() is to remain on screen for a set duration. I would like them to keep being displayed as long as the user has not closed them by clicking on "x", but I don't know how to do that.

I also tried using pushMessage()instead of pushCritical(), as it allows you to specify a duration and thus could make the message "permanent" if I specified a very long duration, but I can't get it to work. The instruction

self.iface.messageBar().pushMessage(u'Error : ', u' My error message.', level=QgsMessageBar.CRITICAL, duration=999)

gets me the following error in the console : NameError: global name 'QgsMessageBar' is not defined. I don't understand what the problem is, I used from PyQt4.QtGui import * at the beginning of my script...

1 Answer 1

3

QgsMessageBar comes from the qgis.gui module, not from PyQt4.QtGui :)

So you could use something like the following:

from qgis.gui import QgsMessageBar

self.iface.messageBar().pushMessage(u'Error : ', u' My message.', level = QgsMessageBar.CRITICAL, duration=0)

Where the integer 0 indicates a no timeout (i.e. no duration).

0

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.