[PyQt] Problem using promoted widgets with PyQt 4.4.2

Phil Thompson phil at riverbankcomputing.com
Wed Jul 30 12:01:27 BST 2008


On Wed, 30 Jul 2008 13:47:55 +0300, Jan Ekholm <jan.ekholm at smultron.net>
wrote:
> 
> Hi,
> 
> Yesterday I upgraded to PyQt 4.4.2 as such a package was available as a
> part 
> of the Kubuntu packages for KDE 4.1. Didn't think too much about it, but
> now 
> that I try to run my photo management app I get some problems that I
can't
> 
> seem to solve. The application heavily relies on promoted widgets and
that
> 
> has worked fine since I moved the app to PyQt4 some years ago. Now with
> 4.4.2 
> I get this when I try to run a minimal cut down part of the app:
> 
> % python tags.py
> Traceback (most recent call last):
>   File "tags.py", line 64, in <module>
>     Tags().show()
>   File "tags.py", line 19, in __init__
>     loadUi("tags.ui", self)
>   File "/usr/lib/python2.5/site-packages/PyQt4/uic/__init__.py", line
106,
> in 
> loadUi
>     return loader.DynamicUILoader().loadUi(uifile, baseinstance)
>   File "/usr/lib/python2.5/site-packages/PyQt4/uic/Loader/loader.py",
line
> 22, 
> in loadUi
>     return self.parse(filename)
>   File "/usr/lib/python2.5/site-packages/PyQt4/uic/uiparser.py", line
572,
> in 
> parse
>     actor(elem)
> 
> <snip some levels>
> 
>   File "/usr/lib/python2.5/site-packages/PyQt4/uic/uiparser.py", line
155,
> in 
> createWidget
>     self.stack.push(self.setupObject(widgetClass(elem), parent, elem))
>   File "/usr/lib/python2.5/site-packages/PyQt4/uic/uiparser.py", line
130,
> in 
> setupObject
>     obj =  self.factory.createQObject(clsname, name, args, is_attribute)
>   File "/usr/lib/python2.5/site-packages/PyQt4/uic/objcreator.py", line
> 59, in 
> createQObject
>     classType = self.findQObjectType(classname)
>   File "/usr/lib/python2.5/site-packages/PyQt4/uic/objcreator.py", line
> 67, in 
> findQObjectType
>     w = module.search(classname)
>   File
> "/usr/lib/python2.5/site-packages/PyQt4/uic/Loader/qobjectcreator.py", 
> line 48, in search
>     return getattr(self._modules[module], cls)
> AttributeError: 'module' object has no attribute 'KeywordTree'
> 
> The class KeywordTree is a promoted widget that inherits QTreeWidget and
> this 
> worked fine with older versions of PyQt4 (the version shipped with
Kubuntu
> 
> Hardy). The .ui file is loaded dynamically with loadUi() and the actual
> .ui 
> file is attached.
> 
> Relevant sections from the .ui seem to be the usage of the KeywordTree
> widget:
> 
>     <widget class="KeywordTree" name="keyword_tree" >
>      <column>
>       <property name="text" >
>        <string>1</string>
>       </property>
>      </column>
>     </widget>
> 
> And the promoted data:
> 
>  <customwidgets>
>   <customwidget>
>    <class>KeywordTree</class>
>    <extends>QTreeWidget</extends>
>    <header>keyword_tree.h</header>
>   </customwidget>
>  </customwidgets>
> 
> The real KeywordTree class is in a file keyword_tree.py and simply
defines
> a 
> QtGui.QTreeWidget subclass. This has worked for years. Also, some other
> apps 
> that also use promoted widgets work just normally, so the whole 
> promotion/loading mechanism is not broken, only in this case have I
> stumbled 
> across any problems.
> 
> I consider nuking KDE 4.1 if I can't solve this, as this application is
> *very* 
> important for us. But perhaps there's something that a n00b like me
hasn't
> 
> spotted? Something that used to work despite it being wrong?

You haven't provided enough to allow the problem to be reproduced, but if
you run pyuic4 from the current snapshot and replace...

from keyword_tree import KeywordTree

...with...

from PyQt4.QtGui import QTreeWidget as KeywordTree

...then running the generated code seems to work.

Phil



More information about the PyQt mailing list