20130308
I use MessageBox in pyQt and want to change default button from Yes to No, let see how to do.
first I want to show the basic command to show message box
from PyQt4 import QtGui
reply = QtGui.QMessageBox.question(None,'Warning!!','Click [Yes] to do or [No] to skip',QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)
if reply == QtGui.QMessageBox.Yes:
print 'Yes'
else:
print 'No'
output show in image the default button is highlight on Yes button
when we want to change default from Yes to No button we can do like this
from PyQt4 import QtGui
reply = QtGui.QMessageBox.question(None,'Warning!!','Click [Yes] to do or [No] to skip',QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.No)
if reply == QtGui.QMessageBox.Yes:
print 'Yes'
else:
print 'No'
the “QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.No” is key point first two are what button to show, this word meas show Yes and No button and after comma is what default button now I set No button and the result is


