Sunday, 3 May 2015

qgis - How to address the new "Task-Completed" QgsMessageBar in Python?


I am really amazed what huge steps the QGIS development has taken in the last months. The new iconset, the improved Print composer and many more changes to be seen in QGIS 2.0 are really awesome!


Among many other cool improvements there is also this nifty blue task-bar, which I find very appealing. Text says: Save completed: Export to vector file finished


Is it possible to address this bar in python for scripts and plugins (for instance to show a small message after finished computations)? I am asking this question here, because i believe that many QGIS developers also visit this Q&A site.


PS: The bar is only visible in QGIS dev and only for some operations.




Answer



It sure is:


iface.messageBar().pushMessage("Header","MessageBody", QgsMessageBar.WARNING, 2)

the last arg is a timeout in seconds, if it's not supplied then it will stay until the user closes it.


You can even add you own control to the messagebar:


widget = iface.messageBar().createMessage("Test","Testing")
combo = QComboBox()
widget.layout().addWidget(combo)
iface.messageBar().pushWidget(widget, QgsMessageBar.WARNING)

combo.addItems("ASD")

enter image description here


http://www.qgis.org/api/classQgsMessageBar.html#a0b305c7215d75243b4237c299f0f7723


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...