4

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:
    ????
10

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
else:
    #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)
1
  • 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. – Jesse McMillan Jan 12 '16 at 7: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.