There is a simple code to add message bar to main window in QGIS:


My question is how to add bar to my custom canvas canvas = QgsMapCanvas() in standalone application? Is there possibility to display it on the bottom of canvas?


1 Answer 1


It's just a widget so you sure can. Normally you would add it to a layout however that will resize your canvas when it pops up which is a bit annoying IMO. What you can do is just some logic to resize the bar to match the parent size when it is shown.

Here is some code that I use to do just that:

class MessageBar(QgsMessageBar):
    def __init__(self, parent=None):
        super(MessageBar, self).__init__(parent)

    def showEvent(self, event):
        self.resize(QSize(self.parent().geometry().size().width(), self.height()))
        self.move(0, self.parent().geometry().size().height() - self.height())

    def eventFilter(self, object, event):
        if event.type() == QEvent.Resize:

        return super(MessageBar, self).eventFilter(object, event)


canvas = QgsMapCanvas()
messagebar = MessageBar(canvas)
messagebar.pushMessage("title", "message")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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