Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QMessageBox change text of standard button

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)
like image 502
Taylan Avatar asked Mar 09 '16 09:03

Taylan


2 Answers

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
like image 119
Daniele Pantaleone Avatar answered Nov 06 '22 17:11

Daniele Pantaleone


Qt provides translations for all the built-in strings it uses in its libraries. You just need to install a translator for the current locale:

app = QtGui.QApplication(sys.argv)

translator = QtCore.QTranslator(app)
locale = QtCore.QLocale.system().name()
path = QtCore.QLibraryInfo.location(QtCore.QLibraryInfo.TranslationsPath)
translator.load('qt_%s' % locale, path)
app.installTranslator(translator)
like image 8
ekhumoro Avatar answered Nov 06 '22 18:11

ekhumoro