[PyKDE] KXMLGUIFactory.container()

Gordon Tyler gordon at doxxx.net
Sun Apr 13 07:07:00 BST 2003


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>&amp;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?

Thanks,
Gordon




More information about the PyQt mailing list