[英]pyside, Qt Designer, encapsulated code, and AttributeError: 'MainWindow' object has no attribute 'QtGui'
I used Qt Designer to create a .ui file then pyside-uic to convert to a .py file (ui_mainWindow.py with class Ui_MainWindow
). 我使用Qt Designer创建.ui文件,然后使用pyside-uic转换为.py文件(具有类Ui_MainWindow
)。 I'm heeding the warning not to edit the .ui or .py because any changes there will be overwritten when saving updates in Qt Designer. 我注意不要编辑.ui或.py的警告,因为在Qt Designer中保存更新时,那里的所有更改都将被覆盖。 So I have my own separate code that should be inheriting from it using the python's super
functionality. 所以我有自己的单独代码,应该使用python的super
功能从其继承。
class MainWindow(QMainWindow, Ui_MainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.setupUi(self)
self.assignWidgets()
self.show()
I'm able to update labels and respond to buttons and such but I'm not able to use the localization translation stuff. 我可以更新标签并响应按钮等,但是我无法使用本地化翻译内容。 Part of the above class is this function: 上面的类的一部分是此函数:
def connecetSerialPushed(self):
self.label_connected.setText(self.QtGui.QApplication.translate(self, "Connected: Yes", None, self.QtGui.QApplication.UnicodeUTF8))
If I just do a pure setText
and the "Connected: Yes"
string, I get no error. 如果我只是执行一个纯setText
和"Connected: Yes"
字符串,则不会出现任何错误。 But doing that translation results in an error: AttributeError: 'MainWindow' object has no attribute 'QtGui'. 但是执行该转换会导致错误:AttributeError:'MainWindow'对象没有属性'QtGui'。 I don't get it.. I thought I inherited everything from Ui_MainWindow
including it's import of QtGui
. 我不明白。.我以为我继承了Ui_MainWindow
所有内容,包括QtGui
的导入。 What am I missing? 我想念什么?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.