3

I am building a plugin in QGis and I want to activate the plugin icon again when user clicks cancel button in the message box.

def run(self, checked):
    if checked == True:
        # icon is active
        # do something
    if checked == False:
        # icon is deactive
        reply = QtGui.QMessageBox.question(self.iface.mainWindow(), 'Continue?', 
             'message', QtGui.QMessageBox.Yes, QtGui.QMessageBox.Cancel)
        if reply == QtGui.QMessageBox.Yes:
            # do something
        if reply == QtGui.QMessageBox.Cancel:
            # set the tool icon active again
            # do nothing

Maybe my solution is not the best one.

1

Perhaps use something like the following:

def run(self, checked):
    if checked:
        # icon is active
        print 'Do something'
    else:
        # icon is deactive
        reply = QtGui.QMessageBox.question(self.iface.mainWindow(), 'Continue?', 
            'message', QtGui.QMessageBox.Yes, QtGui.QMessageBox.Cancel)
        if reply == QtGui.QMessageBox.Yes:
            # do something
            print 'Yes'
        else:
            # set the tool icon active again
            # do nothing
            self.your_icon.setChecked(True)

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.