QMessageBox change text of standard button

Taylan picture Taylan · Mar 9, 2016 · Viewed 11.5k times · Source

I want to use QMessageBox.Question for the icon. But i want to change the text of standard buttons. I do not want the text of buttons to be the "Yes" and "No". I want them to be "Evet" and "Iptal". Here my codes.

choice = QtGui.QMessageBox.question(self, 'Kaydet!',
                                    'Kaydetmek İstediğinize Emin Misiniz?',
                                    QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)

Answer

Daniele Pantaleone picture Daniele Pantaleone · Mar 9, 2016

To do so you need to create an instance of a QMessageBox and manually change the text of the buttons:

box = QtGui.QMessageBox()
box.setIcon(QtGui.QMessageBox.Question)
box.setWindowTitle('Kaydet!')
box.setText('Kaydetmek İstediğinize Emin Misiniz?')
box.setStandardButtons(QtGui.QMessageBox.Yes|QtGui.QMessageBox.No)
buttonY = box.button(QtGui.QMessageBox.Yes)
buttonY.setText('Evet')
buttonN = box.button(QtGui.QMessageBox.No)
buttonN.setText('Iptal')
box.exec_()

if box.clickedButton() == buttonY:
    # YES pressed
elif box.clickedButton() == buttonN:
    # NO pressed