I like the idea of using the loadUi() method in PyQt to load in a QtDesigner interface file as I'm often changing the ui file and don't want to be constantly converting it to a py file.
However, I've been having difficulty understanding how to access the different widgets and views in my ui file. The below shows how I'm loading in the ui:
class MyClass(QtGui.QMainWindow):
def __init__(self, parent = None):
super().__init__(parent)
ui = uic.loadUi('MyUserInterface.ui',self)
if __name__ == '__main__':
import sys
app = QtGui.QApplication(sys.argv)
mainapplication = MyClass()
mainapplication.show()
app.exec_()
It displays fine, but I was expecting that I would be able to access the elements of the GUI by something along the lines of...
ui.sampleButton.makeDraggable()
My question is, how can I access the various elements within my GUI?
Edit 1: I Also have tried to without assigning the uic.load call to ui. When accessing as shown below, I can access some of the properties through using Ui_MainWindow. However, it throws an error
if __name__ == '__main__':
import sys
app = QtGui.QApplication(sys.argv)
mainapplication = MyClass()
mainapplication.Ui_MainWindow.graphicsView.acceptDrops(True)
mainapplication.show()
app.exec_()
The error i get is...
Traceback (most recent call last): File "C:\Users\Me\workspaces\com.samplesoftware.software\src\SoftwareView\MyClass.py", line 17, in <module>
mainapplication.Ui_MainWindow.graphicsView.acceptDrops(True)
AttributeError: 'MyClass' object has no attribute 'Ui_MainWindow'
Any ideas?