Thursday, April 21, 2011

PyQt: translating standard buttons

How can I easily translate standard buttons (Yes, No) from QMessageBox? I can't use self.tr on those arguments, so I would like to achieve it in some other simple way. Do I have to use whole translation system?

From stackoverflow
  • Are you sure you have to translate them yourself? In other toolkits, standard buttons are automatically translated to the language that the user is using.

    gruszczy : No, I would prefer to have them translated automatically. But I have no idea how to achieve this.
    DoR : What OS are you using? Have you tried logging in using a different language?
    gruszczy : Ubuntu 9.10 I have everything in polish.
  • The quickest way is something like this:

    mymessagebox.button(mymessagebox.Yes).setText("Yes, please!")
    mymessagebox.button(mymessagebox.No).setText("No, thanks.")
    

    See the QMessageBox documentation for all possible standard buttons.

    gruszczy : This seems nice. Thanks.
    gruszczy : OK, this isn't really what I need - I am using question method and I can't really access QMessageBox instance to set this text. Can I achieve this in some other way?

0 comments:

Post a Comment