I am trying to migrate a plugin to QGIS 3 from QGIS 2 and I am having issues with an API.

The original Python has QgsMessageBar.MessageLevel but https://qgis.org/api/api_break.html says it has been moved to Qgis::MessageLevel. I tried replacing it in the code and got an invalid syntax and I couldn't find a MessageLevel example in Python 3.

What does it mean when something has been moved to Qgis::...? How do I find the proper syntax and use?

  • which syntax did u try so far ?
    – Snaileater
    Mar 29, 2019 at 19:17

2 Answers 2


You can make a util function like this

from qgis.core import Qgis

def showUserMessage(before, text="", level=Qgis.Info, duration=3):
    ''' Show user info/warning/error messages '''
    iface.messageBar().pushMessage(before, text, level=level, duration=duration)

showUserMessage("Info : ", "Info Sample")
showUserMessage("Warning : ", "Warning Sample", Qgis.Warning)
showUserMessage("Critical : ", "Critical Sample", Qgis.Critical)
  • Thanks, this got me moving on to the next error... Apr 1, 2019 at 11:32

The proper syntax is like below:

# First import Qgis class
from qgis.core import Qgis


def something():
    # Then you have to use like 'Qgis.MessageLevel' (Qgis.Info as an example)
    iface.messageBar().pushMessage(text, level=Qgis.Info)

For more information, please review Communicating with the user and QGIS API Documentation.

  • Both answers are really close and got me going again; I accepted Fran Raga as the answer because that one simply looked more like the code I was working with so I figured out what needed to change. Now that I see the changes I can see just how similar these 2 answers are... Apr 1, 2019 at 11:34

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.