[PyKDE] QPopupMenu Question
Gordon Tyler
gordon at doxxx.net
Thu Aug 1 16:26:00 BST 2002
From: "Bart Verwilst" <verwilst at gentoo.org>
> I have a QPopup, as follows:
>
> MyPopup = QPopupMenu(self.win.lstSearch, "Popup")
> MyPopup.insertItem( "Function 1", self.myfunction())
> MyPopup.insertItem( "Funciton 2", self.myfunction2())
> MyPopup.popup(QCursor.pos())
>
> The menu shows fine, but as soon as the menu appears, both function 1 and
> function 2 are executed, and then actually clicking on either one of them
> doesn't execute it... It's a floating popup btw, not a fixed one in a
> menubar.. Thanks!
The syntax you have there will call myfunction when you are inserting the
items into the popup. You want the following:
MyPopup = QPopupMenu(self.win.lstSearch, "Popup")
MyPopup.insertItem( "Function 1", self.myfunction)
MyPopup.insertItem( "Funciton 2", self.myfunction2)
MyPopup.popup(QCursor.pos())
Note the lack of () after self.myfunction and self.myfunction2. Without the
() they refer to the functions' _object_ (functions are code objects in
python) and passes that function object to the popup item as the action.
Ciao,
Gordon
More information about the PyQt
mailing list