[英]Starting with Qt Designer and PyQt
I love Python and I have heard a lot about Qt, so lately I've started creating simple GUI applications. 我喜欢Python,并且听说过很多有关Qt的信息,所以最近我开始创建简单的GUI应用程序。 When I convert by pyuic *.ui file to *.py everything looks familiar, understandable and reasonable.
当我将pyuic * .ui文件转换为* .py时,一切看起来都很熟悉,可理解且合理。 Except for one moment.
除了片刻。
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
and then a lot of lines like: 然后很多行像:
MainWindow.setObjectName(_fromUtf8("MainWindow"))
self.label_5.setObjectName(_fromUtf8("label_5"))
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow", None))
self.label_5.setText(_translate("MainWindow", "Surname", None))
When I create any application without using _fromUtf8() and _translate() methods like: 当我不使用_fromUtf8()和_translate()方法创建任何应用程序时:
MainWindow.setObjectName("MainWindow")
self.label_5.setText("Surname")
everything works as well. 一切正常。
So, here is a question: Do I really need to use _fromUtf8() and _translate() methods? 所以,这是一个问题:我真的需要使用_fromUtf8()和_translate()方法吗?
If yes, why? 如果是,为什么?
Thanks in advance. 提前致谢。
These methods are utilized for internationalization of your application. 这些方法用于您的应用程序的国际化。 If you are not planning on ever supporting the UI in multiple languages, then you can disable all of the
translatable
settings on your Widget. 如果您不打算支持多种语言的UI,则可以禁用Widget上的所有可
translatable
设置。
Several Widgets have multiple areas that have this setting. 几个小部件具有多个具有此设置的区域。 For example, a
QLabel
has 4: 例如,一个
QLabel
有4个:
The _fromUtf8
is utilized if you are using a language that utilizes characters that occupy more than ASCII characters (think anything with diacritics or multi-byte characters). 如果使用的语言使用的字符占用的字符数超过ASCII字符(请考虑任何带有变音符号或多字节字符的字符),则可以使用
_fromUtf8
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.