Qt-interest Archive, January 2007
QGraphics - Context Menu
Message 1 in thread
Hi,
I would like implement context menu in QGraphics. I tried reimplement
contextMenuEvent in a class that Inherit from QGraphicsView and then
call exec method, but doesn't work.
class X : public QGraphicsView
{
X (QWidget *parent = 0);
private:
QAction *test;
void contextMenuEvent (QGraphicsSceneContextMenuEvent *);
};
X::X (QWidget *parent)
: QGraphicsView (parent)
{
test = new QAction ("&Test", parent);
}
void X::contextMenuEvent (QGraphicsSceneContextMenuEvent *e)
{
QMenu *menu = new QMenu;
menu->addAction(action_test);
menu->exec(e->scenePos());
}
Can anyone help me?
Thanks,
--
[ signature omitted ]
Message 2 in thread
On Tue, Jan 23, Kung Te Yang wrote:
> Hi,
>
> I would like implement context menu in QGraphics. I tried reimplement
> contextMenuEvent in a class that Inherit from QGraphicsView and then
> call exec method, but doesn't work.
>
> class X : public QGraphicsView
> {
> X (QWidget *parent = 0);
>
> private:
> QAction *test;
>
> void contextMenuEvent (QGraphicsSceneContextMenuEvent *);
>
> };
>
> X::X (QWidget *parent)
> : QGraphicsView (parent)
> {
> test = new QAction ("&Test", parent);
> }
>
> void X::contextMenuEvent (QGraphicsSceneContextMenuEvent *e)
Here I have in my app:
> void X::contextMenuEvent (QContextMenuEvent *e)
> {
> QMenu *menu = new QMenu;
> menu->addAction(action_test);
> menu->exec(e->scenePos());
context menus are predefined and
contextMenu->popup(e->globalPos() );
Hope that helps,
Uwe
--
[ signature omitted ]