17

Is there any way to show our custom message in Qgis Status bar using python? Just like in arcgis IApplication.statusbar.message(0) = "Please wait..."

like that is there any option to show progressbar in Qgis like IApplication.progressbar.show()

1 Answer 1

38

StatusBar

There is iface.mainWindow().statusBar() which returns a QStatusBar

iface.mainWindow().statusBar().showMessage( u"Hello World" )

enter image description here

MessageBar

Starting from QGIS 2.0 there is also QgsMessageBar which is able to display unobtrusive messages

iface.messageBar().pushInfo(u'My Plugin says', u'Hey there')

enter image description here

Advanced

The message bar can also show any QWidget (like a QProgressBar) with a close button and a timeout (5 seconds in the example).

from PyQt4.QtGui import QProgressBar
from qgis.gui import QgsMessageBar
msgBar = iface.messageBar()

pb = QProgressBar( msgBar )
msgBar.pushWidget( pb, QgsMessageBar.INFO, 5 )

msg = msgBar.createMessage( u'Hello World' )
msgBar.pushWidget( msg, QgsMessageBar.WARNING, 5 )

enter image description here

More info about QgsMessageBar can be found in this answer by NathanW How to address the new "Task-Completed" QgsMessageBar in Python? Thanks for pointing out Curlew

Legacy

In the python console for QGIS < 1.9 it would be:

qgis.utils.iface.mainWindow().statusBar().showMessage( u"Hello World" )
5
  • Thanks a lot Matthias..is there any option for progressbar?
    – venkat
    Commented Apr 22, 2013 at 11:33
  • In the QgsMessageBar you're able to display any kind of widget. I would not know that this is possible in the status bar. Commented Apr 22, 2013 at 11:36
  • I am very new to qgis and python.. could you please give me example for QgsMessageBar? and what is the meaning of using 'u' prefix in "Hello world"
    – venkat
    Commented Apr 22, 2013 at 11:40
  • The u prefix is for unicode strings. It will also work without this. For the QgsMessageBar you have to get the current development version of QGIS or wait for the release of 2.0. Commented Apr 22, 2013 at 11:47
  • 3
    Also see Nathans answer on how to push a widget to the new messagebar gis.stackexchange.com/questions/57067/…
    – Curlew
    Commented Apr 22, 2013 at 13:32

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.