I'm making a QGIS plugin that processes a dataset. I started with pluginbuilder and have a GUI that allows me to set what to do.

As my plugin is making changes, when it detects a certain threshold of changes I want it to pop up a dialog with the old and new values and ask whether to apply changes or skip. How do I do that?

The basic structure so far:

if abs(oldCount - newCount) > 10:

2 Answers 2


Use QMessageBox.question:

from PyQt4 import QtGui
reply = QMessageBox.question(self.iface.mainWindow(), 'Continue?', 
                 'Your message here', QMessageBox.Yes, QMessageBox.No)
if reply == QtGui.QMessageBox.Yes:
    #do something if yes
    #do something if no    

or in console:

from PyQt4 import QtGui
reply = QtGui.QMessageBox.question(iface.mainWindow(), 'Continue?', 
                 'Your message here', QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)
  • Worked great. One thing I ran into was the section of code I wanted to pop open the question was in a different module than the main file so I had to pass the iface on to the module.
    – J M
    Jan 12, 2016 at 7:34

Maxim's answer is great, but now a little outdated. For console try:

from qgis.PyQt.QtWidgets import QMessageBox

promptReply = QMessageBox.question(iface.mainWindow(), 'Prompt', 'Click a button', QMessageBox.Yes, QMessageBox.No)
if promptReply == QMessageBox.Yes:
    print("You clicked yes")
    print("You clicked no")

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.