Issue
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
). 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. So I have my own separate code that should be inheriting from it using the python's super
functionality.
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. But doing that translation results in an error: AttributeError: 'MainWindow' object has no attribute 'QtGui'. I don't get it.. I thought I inherited everything from Ui_MainWindow
including it's import of QtGui
. What am I missing?
Solution
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.
Answered By - James Paul Mason
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.