简体   繁体   English

pyside,Qt Designer,封装的代码和AttributeError:“ MainWindow”对象没有属性“ QtGui”

[英]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? 我想念什么?

Inside my separate code, I did 在单独的代码中,我确实

from PySide import QtGui

and then changed the translation line to 然后将翻译行更改为

self.label_connected.setText(QtGui.QApplication.translate("MainWindow", "Connected: Yes", None, QtGui.QApplication.UnicodeUTF8))

Thanks ray for clearing up my confusion. 谢谢消除我的困惑。

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

相关问题 AttributeError:“ PySide.QtGui.QPixmap”对象没有属性“ setDevicePixelRatio” - AttributeError: 'PySide.QtGui.QPixmap' object has no attribute 'setDevicePixelRatio' PySide.QtGui.QListWidget'对象没有属性'setItemSelected' - PySide.QtGui.QListWidget' object has no attribute 'setItemSelected' PySide6 - Qt Designer ui 对象没有属性“load_pages” - PySide6 - Qt Designer ui object has no attribute 'load_pages' Python AttributeError:“ UI_MainWindow”对象没有属性 - Python AttributeError: 'UI_MainWindow' object has no attribute AttributeError:'Ui_MainWindow'对象没有属性'setCentralWidget' - AttributeError: 'Ui_MainWindow' object has no attribute 'setCentralWidget' AttributeError: 'Ui_MainWindow' object 没有属性 'close' - AttributeError: 'Ui_MainWindow' object has no attribute 'close' PySide2:AttributeError:'NoneType' object 没有属性'objectName' - PySide2 : AttributeError: 'NoneType' object has no attribute 'objectName' AttributeError: 模块“PyQt5.QtGui”没有属性“QWidget” - AttributeError: module 'PyQt5.QtGui' has no attribute 'QWidget' Pyside的Matplotlib与Qt设计师(PySide) - Matplotlib in Pyside with Qt designer (PySide) AttributeError: 'tuple' object 没有以下代码的属性 - AttributeError: 'tuple' object has no attribute for the code below
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM