【问题标题】:QtDesigner Pyqt / Pyside disable translatable by defaultQtDesigner Pyqt / Pyside 默认禁用可翻译
【发布时间】:2019-02-01 10:06:58
【问题描述】:

是否可以将 qtdesigner 中所有内容的可翻译复选框设置为默认禁用。我只需要一种语言,并且更喜欢更简洁的自动生成代码,将 retranslateUI 函数留空并在构造函数中设置所有内容。

将所有内容的复选框设置为禁用非常烦人。

【问题讨论】:

    标签: python pyqt qt-designer uic


    【解决方案1】:

    Qt设计器不允许这样做,这是插件的默认配置,所以我会提出一个解决方法,用一个小脚本修改.ui来禁用该属性:

    from PyQt4 import QtCore, QtXml
    
    if __name__ == '__main__':
    
        filename = "/path/of/your_file.ui"
    
        file = QtCore.QFile(filename)
        if not file.open(QtCore.QFile.ReadOnly):
            sys.exit(-1)
    
        doc = QtXml.QDomDocument()
        if not doc.setContent(file):
            sys.exit(-1)
        file.close()
    
        strings = doc.elementsByTagName("string")
        for i in range(strings.count()):
            strings.item(i).toElement().setAttribute("notr", "true")
    
        if not file.open(QtCore.QFile.Truncate|QtCore.QFile.WriteOnly):
            sys.exit(-1)
    
        xml = doc.toByteArray()
        file.write(xml)
        file.close()
    

    注意:

    该脚本与 PyQt4、PyQt5、PySide 和 PySide2 兼容,它们应该只将 PyQt4 更改为其他库的名称。

    【讨论】:

      猜你喜欢
      • 2018-05-13
      • 1970-01-01
      • 2012-07-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-21
      • 1970-01-01
      相关资源
      最近更新 更多