[PyQt] Error when attempting to use load UI files into Python
Scott Lanahan
lanahans at gmail.com
Wed Sep 12 23:43:10 BST 2012
Hi,
I'm desperately trying to use uic.loadUi to load my main window into
Python. I cannot get it to work for the main window, but it works fine for
various widgets that are in the same Qt project. When I try to load the .ui
file, I get the following error:
Traceback (most recent call last):
File "options.py", line 25, in <module>
myapp = uic.loadUi('mainwindow.ui')
File "/usr/lib/python2.7/site-packages/PyQt4/uic/__init__.py", line 223,
in loadUi
return DynamicUILoader(package).loadUi(uifile, baseinstance)
File "/usr/lib/python2.7/site-packages/PyQt4/uic/Loader/loader.py", line
71, in loadUi
return self.parse(filename, basedir)
File "/usr/lib/python2.7/site-packages/PyQt4/uic/uiparser.py", line 929,
in parse
actor(elem)
File "/usr/lib/python2.7/site-packages/PyQt4/uic/uiparser.py", line 770,
in createUserInterface
self.traverseWidgetTree(elem)
File "/usr/lib/python2.7/site-packages/PyQt4/uic/uiparser.py", line 748,
in traverseWidgetTree
handler(self, child)
File "/usr/lib/python2.7/site-packages/PyQt4/uic/uiparser.py", line 224,
in createWidget
self.traverseWidgetTree(elem)
File "/usr/lib/python2.7/site-packages/PyQt4/uic/uiparser.py", line 748,
in traverseWidgetTree
handler(self, child)
File "/usr/lib/python2.7/site-packages/PyQt4/uic/uiparser.py", line 459,
in createLayout
self.traverseWidgetTree(elem)
File "/usr/lib/python2.7/site-packages/PyQt4/uic/uiparser.py", line 748,
in traverseWidgetTree
handler(self, child)
File "/usr/lib/python2.7/site-packages/PyQt4/uic/uiparser.py", line 502,
in handleItem
self.traverseWidgetTree(elem)
File "/usr/lib/python2.7/site-packages/PyQt4/uic/uiparser.py", line 748,
in traverseWidgetTree
handler(self, child)
File "/usr/lib/python2.7/site-packages/PyQt4/uic/uiparser.py", line 224,
in createWidget
self.traverseWidgetTree(elem)
File "/usr/lib/python2.7/site-packages/PyQt4/uic/uiparser.py", line 748,
in traverseWidgetTree
handler(self, child)
File "/usr/lib/python2.7/site-packages/PyQt4/uic/uiparser.py", line 224,
in createWidget
self.traverseWidgetTree(elem)
File "/usr/lib/python2.7/site-packages/PyQt4/uic/uiparser.py", line 748,
in traverseWidgetTree
handler(self, child)
File "/usr/lib/python2.7/site-packages/PyQt4/uic/uiparser.py", line 459,
in createLayout
self.traverseWidgetTree(elem)
File "/usr/lib/python2.7/site-packages/PyQt4/uic/uiparser.py", line 748,
in traverseWidgetTree
handler(self, child)
File "/usr/lib/python2.7/site-packages/PyQt4/uic/uiparser.py", line 502,
in handleItem
self.traverseWidgetTree(elem)
File "/usr/lib/python2.7/site-packages/PyQt4/uic/uiparser.py", line 748,
in traverseWidgetTree
handler(self, child)
File "/usr/lib/python2.7/site-packages/PyQt4/uic/uiparser.py", line 459,
in createLayout
self.traverseWidgetTree(elem)
File "/usr/lib/python2.7/site-packages/PyQt4/uic/uiparser.py", line 748,
in traverseWidgetTree
handler(self, child)
File "/usr/lib/python2.7/site-packages/PyQt4/uic/uiparser.py", line 502,
in handleItem
self.traverseWidgetTree(elem)
File "/usr/lib/python2.7/site-packages/PyQt4/uic/uiparser.py", line 748,
in traverseWidgetTree
handler(self, child)
File "/usr/lib/python2.7/site-packages/PyQt4/uic/uiparser.py", line 224,
in createWidget
self.traverseWidgetTree(elem)
File "/usr/lib/python2.7/site-packages/PyQt4/uic/uiparser.py", line 748,
in traverseWidgetTree
handler(self, child)
File "/usr/lib/python2.7/site-packages/PyQt4/uic/uiparser.py", line 224,
in createWidget
self.traverseWidgetTree(elem)
File "/usr/lib/python2.7/site-packages/PyQt4/uic/uiparser.py", line 748,
in traverseWidgetTree
handler(self, child)
File "/usr/lib/python2.7/site-packages/PyQt4/uic/uiparser.py", line 459,
in createLayout
self.traverseWidgetTree(elem)
File "/usr/lib/python2.7/site-packages/PyQt4/uic/uiparser.py", line 748,
in traverseWidgetTree
handler(self, child)
File "/usr/lib/python2.7/site-packages/PyQt4/uic/uiparser.py", line 502,
in handleItem
self.traverseWidgetTree(elem)
File "/usr/lib/python2.7/site-packages/PyQt4/uic/uiparser.py", line 748,
in traverseWidgetTree
handler(self, child)
File "/usr/lib/python2.7/site-packages/PyQt4/uic/uiparser.py", line 459,
in createLayout
self.traverseWidgetTree(elem)
File "/usr/lib/python2.7/site-packages/PyQt4/uic/uiparser.py", line 748,
in traverseWidgetTree
handler(self, child)
File "/usr/lib/python2.7/site-packages/PyQt4/uic/uiparser.py", line 502,
in handleItem
self.traverseWidgetTree(elem)
File "/usr/lib/python2.7/site-packages/PyQt4/uic/uiparser.py", line 748,
in traverseWidgetTree
handler(self, child)
File "/usr/lib/python2.7/site-packages/PyQt4/uic/uiparser.py", line 224,
in createWidget
self.traverseWidgetTree(elem)
File "/usr/lib/python2.7/site-packages/PyQt4/uic/uiparser.py", line 748,
in traverseWidgetTree
handler(self, child)
File "/usr/lib/python2.7/site-packages/PyQt4/uic/uiparser.py", line 224,
in createWidget
self.traverseWidgetTree(elem)
File "/usr/lib/python2.7/site-packages/PyQt4/uic/uiparser.py", line 748,
in traverseWidgetTree
handler(self, child)
File "/usr/lib/python2.7/site-packages/PyQt4/uic/uiparser.py", line 459,
in createLayout
self.traverseWidgetTree(elem)
File "/usr/lib/python2.7/site-packages/PyQt4/uic/uiparser.py", line 748,
in traverseWidgetTree
handler(self, child)
File "/usr/lib/python2.7/site-packages/PyQt4/uic/uiparser.py", line 502,
in handleItem
self.traverseWidgetTree(elem)
File "/usr/lib/python2.7/site-packages/PyQt4/uic/uiparser.py", line 748,
in traverseWidgetTree
handler(self, child)
File "/usr/lib/python2.7/site-packages/PyQt4/uic/uiparser.py", line 215,
in createWidget
self.stack.push(self.setupObject(widget_class, parent, elem))
File "/usr/lib/python2.7/site-packages/PyQt4/uic/uiparser.py", line 176,
in setupObject
obj = self.factory.createQObject(clsname, name, args, is_attribute)
File "/usr/lib/python2.7/site-packages/PyQt4/uic/objcreator.py", line
124, in createQObject
return self._cpolicy.instantiate(factory, *args, **kwargs)
File
"/usr/lib/python2.7/site-packages/PyQt4/uic/Loader/qobjectcreator.py", line
131, in instantiate
return clsObject(*ctor_args)
TypeError: __init__() takes exactly 1 argument (2 given)
Here is the code I am trying to run:
class mainWindow(QtGui.QMainWindow):
def __init__(self,parent=None):
QtGui.QMainWindow.__init__(self, parent)
self.ui = uic.loadUi('mainwindow.ui', self)
if __name__ == "__main__":
QtGui.QApplication.setStyle(QtGui.QStyleFactory.create("Cleanlooks"))
QtGui.QApplication.setPalette(QtGui.QApplication.style().standardPalette())
app = QtGui.QApplication(sys.argv)
myapp = mainWindow()
myapp.show()
sys.exit(app.exec_())
My google-fu is usually very strong, but I have been unable to determine
the root of this problem. I have worked and worked on it, but still no
luck. Please help!
Thanks,
Scott
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20120912/3b7e2f01/attachment.html>
More information about the PyQt
mailing list