[PyKDE] KXMLGUIFactory.container()
Phil Thompson
phil at river-bank.demon.co.uk
Sun Apr 13 11:33:00 BST 2003
On Sunday 13 April 2003 6:06 am, Gordon Tyler wrote:
> Hi all,
>
> I have a Python class which inherits KMainWindow. In a slot function on
> this class which is connected to the contextMenuRequested signal of a
> QIconView, I would like to popup a context menu.
>
> I have in my XML GUI RC file the following:
>
> <!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
> <kpartgui name="finder" version="1">
>
> <MenuBar>
> <Menu name="file" noMerge="1"><text>&File</text>
> <Action name="file_open"/>
> <Separator/>
> <Action name="file_properties"/>
> <Separator/>
> <Action name="file_close_window"/>
> </Menu>
> </MenuBar>
>
> <Menu name="context">
> <Action name="file_open"/>
> <Separator/>
> <Action name="file_properties"/>
> </Menu>
>
> </kpartgui>
>
> The "file" menu works fine. But when I try to do the following (called by
> the slot function):
>
> def displayContextMenu(self, pos):
> menu = self.factory().container("context", self)
> menu.popup(pos)
>
> The object returned in the menu variable is of type QWidget according to
> eric3's debugger, and I get an "AttributeError: popup" exception on the
> next line.
>
> The example C++ code from which I grabbed this used a static_cast to cast
> the object returned by the container method to a QPopupMenu. Is the QWidget
> return type of the container method causing PyQt/sip to wrap whatever is
> returned as a QWidget object regardless of its real type? How would I be
> able to treat the returned object as a QPopupMenu object so that I can call
> its popup method?
This is handled by providing SIP with %ConvertToSubClass code. PyQt provides
the code for all classes that are part of Qt. PyKDE should do the same for
the relevant classes of KDE.
In this case, if KXMLGUIFactory.container() is returning a QPopupMenu then the
existing PyQt support should be enough as only Qt widgets are involved. If,
instead, it is returning a KDE specific sub-class of QPopupMenu, and PyKDE
doesn't provide appropriate %ConvertToSubClass code then it will return the
base type, ie. QWidget.
Factory functions should also have the SIP /Factory/ tag.
Phil
More information about the PyQt
mailing list