简体   繁体   English

retranslateUi()清除QLabel文本

[英]retranslateUi() clears QLabel text

My qt4-based application dynamically changes the GUI language by calling retranslateUi() function. 我的基于qt4的应用程序通过调用retranslateUi()函数动态地更改GUI语言。 It works like a charm, but when it processes the QLabel which text changes by the program, it tries to translate original text - the one, specified in Qt Designer, not the one, set by my program. 它就像一个魅力,但当它处理QLabel时,程序会更改文本,它会尝试翻译原始文本 - 在Qt Designer中指定的文本,而不是由我的程序设置的文本。

I understand it happens because retranslateUi() is auto-generated during build process so it couldn't possibly know about my changes, but I'd prefer to skip such QLabel s completely. 据我所知,因为在构建过程中会自动生成retranslateUi()所以它不可能知道我的更改,但我更愿意完全跳过这样的QLabel Is there a way to tell Qt to skip certain widgets in retranslateUi() ? 有没有办法告诉Qt在retranslateUi()跳过某些小部件? Alternatively, maybe I can disable content change for QLabel in my program? 或者,也许我可以在我的程序中禁用QLabel内容更改?

I know I can sub-class QLabel and by overriding setText() solve this problem, but I prefer to use standard QLabel to be able to manipulate it using Qt Designer. 我知道我可以将QLabel子类化并通过重写setText()解决这个问题,但我更喜欢使用标准的QLabel来使用Qt Designer来操作它。

As I remember, in Designer you can uncheck on QLabel should it be translated. 我记得,在Designer中你可以取消QLabel的翻译。 By default it is. 默认情况下是。 Choose label you don't want to be translated, in property editor scroll to "text" property, expand it and uncheck translate checkbox. 选择您不想翻译的标签,在属性编辑器中滚动到“文本”属性,展开它并取消选中翻译复选框。 Then you should generate ui_*.h file again. 然后你应该再次生成ui _ * .h文件。 After that your label shouldn't be in retranslateUi code 之后,您的标签不应该是retranslateUi代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM