Reputation: 756
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)
Upvotes: 20
Views: 21679
Reputation: 2723
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
Upvotes: 41
Reputation: 120578
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)
Upvotes: 8