[Kde-perl] Right Click Menu

Steffen Liebergeld SteffenL15 at gmx.de
Sat Aug 30 21:51:03 CEST 2003


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.


-- 
mit freundlichen Grüßen
		Steffen Liebergeld



More information about the Kde-perl mailing list