I followed the following tutorial to create a QGIS message bar with widget, but it is being shown as a warning message (orange color). https://docs.qgis.org/3.16/en/docs/pyqgis_developer_cookbook/communicating.html#showing-messages-the-qgsmessagebar-class

enter image description here

But I want to show the message bar as info (blue color) not as warning (orange color). I know there is level parameter in iface.messageBar().pushMessage() which I can set to Qgis.Info but there is no such parameter in iface.messageBar().createMessage() which is used for widget. https://qgis.github.io/pyqgis/3.0/gui/Message/QgsMessageBar.html#qgis.gui.QgsMessageBar.createMessage

How can I change the type of message bar with widget.

1 Answer 1


I figured out that all that is needed is to drop Qgis.Warning in the last line. It will then default to Qgis.Info

def showError():

widget = iface.messageBar().createMessage("Missing Layers", "Show Me")
button = QPushButton(widget)
button.setText("Show Me")
# iface.messageBar().pushWidget(widget, Qgis.Warning)

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.