retranslateUi()清除QLabel文本 [英] retranslateUi() clears QLabel text

查看:3715
本文介绍了retranslateUi()清除QLabel文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的基于qt4的应用程序通过调用 retranslateUi()函数动态更改GUI语言。它的工作方式类似于charm,但是当它处理由程序更改的文本的 QLabel 时,它会尝试翻译原始文本 - 在Qt Designer中指定的文本,而不是一个

My qt4-based application dynamically changes the GUI language by calling retranslateUi() function. 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.

我理解这是因为 retranslateUi()是在构建过程中自动生成的它不可能知道我的更改,但我更喜欢跳过这个 QLabel 完全。有没有办法告诉Qt跳过 retranslateUi()中的某些小部件?或者,我可以在我的程序中禁用 QLabel 的内容更改

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 QLabels completely. Is there a way to tell Qt to skip certain widgets in retranslateUi()? Alternatively, maybe I can disable content change for QLabel in my program?

我知道我可以子类并通过重载 setText()解决这个问题,但我更喜欢使用标准 QLabel ,以便能够使用Qt Designer处理它。

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应该翻译。默认情况下是。选择您不想翻译的标签,在属性编辑器中滚动到文本属性,展开它并取消选中翻译复选框。然后你应该再次生成ui _ *。h文件。之后,您的标签不应该在retranslateUi代码

As I remember, in Designer you can uncheck on QLabel should it be translated. 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. After that your label shouldn't be in retranslateUi code

这篇关于retranslateUi()清除QLabel文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆