[Kde-perl] Right Click Menu

Richard Dale Richard_Dale at tipitina.demon.co.uk
Sat Aug 30 22:06:19 CEST 2003


On Saturday 30 August 2003 19:51, Steffen Liebergeld wrote:
> Am Sam, 2003-08-30 um 19.17 schrieb Richard Dale:
> > On Saturday 30 August 2003 17:34, Steffen Liebergeld wrote:
> > > Hi,
> > >
> > > Iam writing a program (using perl-Qt) including a Qt::ListView Widget.
> > > But I can´t figure out how to add a right-mouse-click menu to this
> > > widget.
> > >
> > > I would be pleased if you could give me a hint.
> >
> > You need to create a popup menu, and subclass Qt::ListView to override
> > mousePressEvent to show the menu if 'event.button() == RightButton'. Here
> > is an example in perl (this might be wrong, I haven't tried the code):
> >
> > 		$popupmenu = Qt::PopupMenu();
> > 		$popupmenu.insertItem("&Clear", this, SLOT("slotClearArea()"));
> >
> > 		sub mousePressEvent() {
> > 			if ($_[0].button() == RightButton) {
> > 				$popupmenu.exec(Qt::Cursor.pos());
> > 				...
> > 			}
> > 		}
>
> should it look like this?
>
> package MyList;
> use strict;
> use Qt;
> use Qt::isa qw(Qt::ListView);
> use Qt::slots;
> use Qt::signals;
> use Qt::attributes qw(rightmenu);
>
> sub NEW{
>     shift->SUPER::NEW(@_);
>     my ($rightmenu) = Qt::PopupMenu(this);
>     $rightmenu->insertTearOffHandle();
>     $rightmenu->insertItem("&Hallo",this,SLOT('clear()'));
>     rightmenu = $rightmenu;
> }
>
>
> sub mousePressEvent{
>     shift->SUPER::NEW(@_);
>     if ($_[0]->button() == "RightButton"){
> 	rightmenu->exec(Qt::Cursor.po());
>     }
> }
>
>
> 1;
>
> It doesn´t do what I want. But wheres my mistake? I´m sorry if the
> problem is obvious, but I can´t figure it out at the moment.
I think the concept should work (I copied the example from the Qt Scribble 
example in the 'Programming With Qt' book and translated it from ruby), even 
though my perl example looks pretty poor perl - what do you mean by 'it 
doesn't do what I want' - what is the specific problem?

-- Richard


More information about the Kde-perl mailing list