Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 4

Qt-interest Archive, April 2007
Handling events in Graphics View Framework


Message 1 in thread

Hi,
 
I am not able to understand what is going on in graphics view framework
relating to event handling.
I tried docs but that didnt really help :-(
 
I have created a contextmenu in QGraphicsView. Now, when I click, does
the event go to the GraphicsView or to the Item->scene->view.
I want to handle contextmenu events in the items. There is a function
provided in QGraphicsItem class 
contextMenuEvent(QGraphicsSceneContextMenuEvent *contextMenuEvent)

I have reimplemented this function for an Item, but the event never
reaches here. 
I believe I cannt set a context menu for the scene or the GraphicsItem
as they are not widgets.
How do I handle the context menu in the items ?
 
Is it also true that I cannot have slots for QGraphicsItem, it gives me
compile time errors if I declase Q_OBJECT in QGraphicsItem derived
class..
 
Thnx
Prateek

 


Message 2 in thread

Have you used 'acceptMouseButtons()' function?

Prateek Tiwari ha scritto:
> Hi,
>  
> I am not able to understand what is going on in graphics view 
> framework relating to event handling.
> I tried docs but that didnt really help :-(
>  
> I have created a contextmenu in QGraphicsView. Now, when I click, does 
> the event go to the GraphicsView or to the Item->scene->view.
> I want to handle contextmenu events in the items. There is a function 
> provided in QGraphicsItem class
>
> contextMenuEvent(QGraphicsSceneContextMenuEvent *contextMenuEvent)
>
> I have reimplemented this function for an Item, but the event never 
> reaches here.
> I believe I cannt set a context menu for the scene or the GraphicsItem 
> as they are not widgets.
> How do I handle the context menu in the items ?
>  
> Is it also true that I cannot have slots for QGraphicsItem, it gives 
> me compile time errors if I declase Q_OBJECT in QGraphicsItem derived 
> class..
>  
> Thnx
> Prateek
>
>  
>

--
 [ signature omitted ] 

Message 3 in thread

Hi Stefano,

All mousebuttons are accepted by default.
Also I am able to move the items on the scene, so the mouse events are
accepted.

This is how I am setting the contextMenu in the view :-

void MyView::createActions()
{
	m_addLineAction = new QAction("DrawLine", this);
	bool ret = connect(m_addLineAction,
SIGNAL(triggered()),this,SLOT(drawEdge()));

	m_addRectAction = new QAction("DrawRectangle", this);
	connect(m_addRectAction,
SIGNAL(triggered()),this,SLOT(drawRect()));

	m_DoNthgAction = new QAction("Draw Nothing", this);
	connect(m_DoNthgAction,
SIGNAL(triggered()),this,SLOT(doNthg()));

	m_copy = new QAction("Copy", this);
	
}

void MyView::createContextMenu()
{
	addAction(m_addLineAction);
	addAction(m_addRectAction);
	addAction(m_DoNthgAction);
	addAction(m_copy);
	setContextMenuPolicy(Qt::ActionsContextMenu);
}

And the control never reaches the Item :-

void TextRect::contextMenuEvent(QGraphicsSceneContextMenuEvent
*contextMenuEvent)
{
	//Never comes here :-(
}

So I dont understand, when does ContextMenuEvent occurs and how is it
propogated to the item :(

--Prateek 

-----Original Message-----
From: Stefano Rosellini [mailto:s.rosellini@xxxxxxxxx] 
Sent: Friday, April 13, 2007 12:28 PM
To: QT Mailing LIST
Subject: Re: Handling events in Graphics View Framework

Have you used 'acceptMouseButtons()' function?

Prateek Tiwari ha scritto:
> Hi,
>  
> I am not able to understand what is going on in graphics view 
> framework relating to event handling.
> I tried docs but that didnt really help :-(
>  
> I have created a contextmenu in QGraphicsView. Now, when I click, does

> the event go to the GraphicsView or to the Item->scene->view.
> I want to handle contextmenu events in the items. There is a function 
> provided in QGraphicsItem class
>
> contextMenuEvent(QGraphicsSceneContextMenuEvent *contextMenuEvent)
>
> I have reimplemented this function for an Item, but the event never 
> reaches here.
> I believe I cannt set a context menu for the scene or the GraphicsItem

> as they are not widgets.
> How do I handle the context menu in the items ?
>  
> Is it also true that I cannot have slots for QGraphicsItem, it gives 
> me compile time errors if I declase Q_OBJECT in QGraphicsItem derived 
> class..
>  
> Thnx
> Prateek
>
>  
>

--
 [ signature omitted ] 

Message 4 in thread

Hi again,

just a guess, try it without changing the contextMenuPolicy from the 
default, i think it
might change the behaviour for the GraphicsView and therefore for the 
GraphicsItems.

And also avoid reimplementing contextMenuEvent of your GraphicsView.

But as I said, just a guess...

Good Luck
Daniel

Prateek Tiwari schrieb:
> Hi Stefano,
>
> All mousebuttons are accepted by default.
> Also I am able to move the items on the scene, so the mouse events are
> accepted.
>
> This is how I am setting the contextMenu in the view :-
>
> void MyView::createActions()
> {
> 	m_addLineAction = new QAction("DrawLine", this);
> 	bool ret = connect(m_addLineAction,
> SIGNAL(triggered()),this,SLOT(drawEdge()));
>
> 	m_addRectAction = new QAction("DrawRectangle", this);
> 	connect(m_addRectAction,
> SIGNAL(triggered()),this,SLOT(drawRect()));
>
> 	m_DoNthgAction = new QAction("Draw Nothing", this);
> 	connect(m_DoNthgAction,
> SIGNAL(triggered()),this,SLOT(doNthg()));
>
> 	m_copy = new QAction("Copy", this);
> 	
> }
>
> void MyView::createContextMenu()
> {
> 	addAction(m_addLineAction);
> 	addAction(m_addRectAction);
> 	addAction(m_DoNthgAction);
> 	addAction(m_copy);
> 	setContextMenuPolicy(Qt::ActionsContextMenu);
> }
>
> And the control never reaches the Item :-
>
> void TextRect::contextMenuEvent(QGraphicsSceneContextMenuEvent
> *contextMenuEvent)
> {
> 	//Never comes here :-(
> }
>
> So I dont understand, when does ContextMenuEvent occurs and how is it
> propogated to the item :(
>
> --Prateek 
>
> -----Original Message-----
> From: Stefano Rosellini [mailto:s.rosellini@xxxxxxxxx] 
> Sent: Friday, April 13, 2007 12:28 PM
> To: QT Mailing LIST
> Subject: Re: Handling events in Graphics View Framework
>
> Have you used 'acceptMouseButtons()' function?
>
> Prateek Tiwari ha scritto:
>   
>> Hi,
>>  
>> I am not able to understand what is going on in graphics view 
>> framework relating to event handling.
>> I tried docs but that didnt really help :-(
>>  
>> I have created a contextmenu in QGraphicsView. Now, when I click, does
>>     
>
>   
>> the event go to the GraphicsView or to the Item->scene->view.
>> I want to handle contextmenu events in the items. There is a function 
>> provided in QGraphicsItem class
>>
>> contextMenuEvent(QGraphicsSceneContextMenuEvent *contextMenuEvent)
>>
>> I have reimplemented this function for an Item, but the event never 
>> reaches here.
>> I believe I cannt set a context menu for the scene or the GraphicsItem
>>     
>
>   
>> as they are not widgets.
>> How do I handle the context menu in the items ?
>>  
>> Is it also true that I cannot have slots for QGraphicsItem, it gives 
>> me compile time errors if I declase Q_OBJECT in QGraphicsItem derived 
>> class..
>>  
>> Thnx
>> Prateek
>>
>>  
>>
>>     
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>   


-- 
 [ signature omitted ] 

Message 5 in thread

Hey Daniel,

It dosent work :-(

The thing is I am not able to propogate any event to the GraphicsItems.
Say even mousePressEvent, I am not able to catch it by overiding
MousePressEvent of the GraphicsItem.

I am able to do so in The QGraphicsView, but the MousePressEvent() for
the Item is just not invoked :-(

I am terribly missing smthg here ....

Thnx
Prateek 

-----Original Message-----
From: Daniel Walz [mailto:walz@xxxxxxxx] 
Sent: Friday, April 13, 2007 3:30 PM
To: QT Mailing LIST
Cc: Prateek Tiwari
Subject: Re: Handling events in Graphics View Framework

Hi again,

just a guess, try it without changing the contextMenuPolicy from the
default, i think it might change the behaviour for the GraphicsView and
therefore for the GraphicsItems.

And also avoid reimplementing contextMenuEvent of your GraphicsView.

But as I said, just a guess...

Good Luck
Daniel

Prateek Tiwari schrieb:
> Hi Stefano,
>
> All mousebuttons are accepted by default.
> Also I am able to move the items on the scene, so the mouse events are

> accepted.
>
> This is how I am setting the contextMenu in the view :-
>
> void MyView::createActions()
> {
> 	m_addLineAction = new QAction("DrawLine", this);
> 	bool ret = connect(m_addLineAction,
> SIGNAL(triggered()),this,SLOT(drawEdge()));
>
> 	m_addRectAction = new QAction("DrawRectangle", this);
> 	connect(m_addRectAction,
> SIGNAL(triggered()),this,SLOT(drawRect()));
>
> 	m_DoNthgAction = new QAction("Draw Nothing", this);
> 	connect(m_DoNthgAction,
> SIGNAL(triggered()),this,SLOT(doNthg()));
>
> 	m_copy = new QAction("Copy", this);
> 	
> }
>
> void MyView::createContextMenu()
> {
> 	addAction(m_addLineAction);
> 	addAction(m_addRectAction);
> 	addAction(m_DoNthgAction);
> 	addAction(m_copy);
> 	setContextMenuPolicy(Qt::ActionsContextMenu);
> }
>
> And the control never reaches the Item :-
>
> void TextRect::contextMenuEvent(QGraphicsSceneContextMenuEvent
> *contextMenuEvent)
> {
> 	//Never comes here :-(
> }
>
> So I dont understand, when does ContextMenuEvent occurs and how is it 
> propogated to the item :(
>
> --Prateek
>
> -----Original Message-----
> From: Stefano Rosellini [mailto:s.rosellini@xxxxxxxxx]
> Sent: Friday, April 13, 2007 12:28 PM
> To: QT Mailing LIST
> Subject: Re: Handling events in Graphics View Framework
>
> Have you used 'acceptMouseButtons()' function?
>
> Prateek Tiwari ha scritto:
>   
>> Hi,
>>  
>> I am not able to understand what is going on in graphics view 
>> framework relating to event handling.
>> I tried docs but that didnt really help :-(
>>  
>> I have created a contextmenu in QGraphicsView. Now, when I click, 
>> does
>>     
>
>   
>> the event go to the GraphicsView or to the Item->scene->view.
>> I want to handle contextmenu events in the items. There is a function

>> provided in QGraphicsItem class
>>
>> contextMenuEvent(QGraphicsSceneContextMenuEvent *contextMenuEvent)
>>
>> I have reimplemented this function for an Item, but the event never 
>> reaches here.
>> I believe I cannt set a context menu for the scene or the 
>> GraphicsItem
>>     
>
>   
>> as they are not widgets.
>> How do I handle the context menu in the items ?
>>  
>> Is it also true that I cannot have slots for QGraphicsItem, it gives 
>> me compile time errors if I declase Q_OBJECT in QGraphicsItem derived

>> class..
>>  
>> Thnx
>> Prateek
>>
>>  
>>
>>     
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with

> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
"unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>   


--
 [ signature omitted ] 

Message 6 in thread

Hey Daniel, 

Another thing I notice :-

As you said, if I do not set a contextmenupolicy in the view, the
contextmenuevent handler is invoked
for the item. But that does not solve the problem. I want to have
different contextmenus for items and the view.

Also, I am not able to capture mousePressEvents in the items, whether or
not I override them in the View.

This is driving me nuts and I not see a good documentation that explains
the working of QGraphics View Framework.
The doc by TT isnt that helpful in this case :-(.

Thnx
Prateek

-----Original Message-----
From: Daniel Walz [mailto:walz@xxxxxxxx] 
Sent: Friday, April 13, 2007 3:30 PM
To: QT Mailing LIST
Cc: Prateek Tiwari
Subject: Re: Handling events in Graphics View Framework

Hi again,

just a guess, try it without changing the contextMenuPolicy from the
default, i think it might change the behaviour for the GraphicsView and
therefore for the GraphicsItems.

And also avoid reimplementing contextMenuEvent of your GraphicsView.

But as I said, just a guess...

Good Luck
Daniel

Prateek Tiwari schrieb:
> Hi Stefano,
>
> All mousebuttons are accepted by default.
> Also I am able to move the items on the scene, so the mouse events are

> accepted.
>
> This is how I am setting the contextMenu in the view :-
>
> void MyView::createActions()
> {
> 	m_addLineAction = new QAction("DrawLine", this);
> 	bool ret = connect(m_addLineAction,
> SIGNAL(triggered()),this,SLOT(drawEdge()));
>
> 	m_addRectAction = new QAction("DrawRectangle", this);
> 	connect(m_addRectAction,
> SIGNAL(triggered()),this,SLOT(drawRect()));
>
> 	m_DoNthgAction = new QAction("Draw Nothing", this);
> 	connect(m_DoNthgAction,
> SIGNAL(triggered()),this,SLOT(doNthg()));
>
> 	m_copy = new QAction("Copy", this);
> 	
> }
>
> void MyView::createContextMenu()
> {
> 	addAction(m_addLineAction);
> 	addAction(m_addRectAction);
> 	addAction(m_DoNthgAction);
> 	addAction(m_copy);
> 	setContextMenuPolicy(Qt::ActionsContextMenu);
> }
>
> And the control never reaches the Item :-
>
> void TextRect::contextMenuEvent(QGraphicsSceneContextMenuEvent
> *contextMenuEvent)
> {
> 	//Never comes here :-(
> }
>
> So I dont understand, when does ContextMenuEvent occurs and how is it 
> propogated to the item :(
>
> --Prateek
>
> -----Original Message-----
> From: Stefano Rosellini [mailto:s.rosellini@xxxxxxxxx]
> Sent: Friday, April 13, 2007 12:28 PM
> To: QT Mailing LIST
> Subject: Re: Handling events in Graphics View Framework
>
> Have you used 'acceptMouseButtons()' function?
>
> Prateek Tiwari ha scritto:
>   
>> Hi,
>>  
>> I am not able to understand what is going on in graphics view 
>> framework relating to event handling.
>> I tried docs but that didnt really help :-(
>>  
>> I have created a contextmenu in QGraphicsView. Now, when I click, 
>> does
>>     
>
>   
>> the event go to the GraphicsView or to the Item->scene->view.
>> I want to handle contextmenu events in the items. There is a function

>> provided in QGraphicsItem class
>>
>> contextMenuEvent(QGraphicsSceneContextMenuEvent *contextMenuEvent)
>>
>> I have reimplemented this function for an Item, but the event never 
>> reaches here.
>> I believe I cannt set a context menu for the scene or the 
>> GraphicsItem
>>     
>
>   
>> as they are not widgets.
>> How do I handle the context menu in the items ?
>>  
>> Is it also true that I cannot have slots for QGraphicsItem, it gives 
>> me compile time errors if I declase Q_OBJECT in QGraphicsItem derived

>> class..
>>  
>> Thnx
>> Prateek
>>
>>  
>>
>>     
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with

> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
"unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>   


--
 [ signature omitted ] 

Message 7 in thread

Prateek Tiwari schrieb:
> Hey Daniel, 
>
> Another thing I notice :-
>
> As you said, if I do not set a contextmenupolicy in the view, the
> contextmenuevent handler is invoked
> for the item. But that does not solve the problem. I want to have
> different contextmenus for items and the view.
>   
You can still do that, but you have to override the 
contextMenuEvent(...) method, which is called
when no item accepted the event in the first place (any event, that is 
ignored is propagated to it's
parent, and as a special case from the root-QGraphicsItem to the 
QGraphicsView AFAIK.
> Also, I am not able to capture mousePressEvents in the items, whether or
> not I override them in the View.
>   
That's strange, I never had any trouble with that...
Some things you might want to check:
- check the name and signature of the eventhandler, if you use e.g. 
QMouseEvent* instead of QSceneMouseEvent*
  it is syntactically ok, but will never be called...  happens sometimes 
to me...  (use copy and paste for the method name directly from the doc...)
- you didn't change 
http://doc.trolltech.com/4.2/qgraphicsitem.html#setAcceptedMouseButtons 
accidently...
- all items being a parent node have 
http://doc.trolltech.com/4.2/qgraphicsitem.html#setHandlesChildEvents 
set to false.

Hope that helps, good luck

Daniel

> This is driving me nuts and I not see a good documentation that explains
> the working of QGraphics View Framework.
> The doc by TT isnt that helpful in this case :-(.
>
> Thnx
> Prateek
>
> -----Original Message-----
> From: Daniel Walz [mailto:walz@xxxxxxxx] 
> Sent: Friday, April 13, 2007 3:30 PM
> To: QT Mailing LIST
> Cc: Prateek Tiwari
> Subject: Re: Handling events in Graphics View Framework
>
> Hi again,
>
> just a guess, try it without changing the contextMenuPolicy from the
> default, i think it might change the behaviour for the GraphicsView and
> therefore for the GraphicsItems.
>
> And also avoid reimplementing contextMenuEvent of your GraphicsView.
>
> But as I said, just a guess...
>
> Good Luck
> Daniel
>
> Prateek Tiwari schrieb:
>   
>> Hi Stefano,
>>
>> All mousebuttons are accepted by default.
>> Also I am able to move the items on the scene, so the mouse events are
>>     
>
>   
>> accepted.
>>
>> This is how I am setting the contextMenu in the view :-
>>
>> void MyView::createActions()
>> {
>> 	m_addLineAction = new QAction("DrawLine", this);
>> 	bool ret = connect(m_addLineAction,
>> SIGNAL(triggered()),this,SLOT(drawEdge()));
>>
>> 	m_addRectAction = new QAction("DrawRectangle", this);
>> 	connect(m_addRectAction,
>> SIGNAL(triggered()),this,SLOT(drawRect()));
>>
>> 	m_DoNthgAction = new QAction("Draw Nothing", this);
>> 	connect(m_DoNthgAction,
>> SIGNAL(triggered()),this,SLOT(doNthg()));
>>
>> 	m_copy = new QAction("Copy", this);
>> 	
>> }
>>
>> void MyView::createContextMenu()
>> {
>> 	addAction(m_addLineAction);
>> 	addAction(m_addRectAction);
>> 	addAction(m_DoNthgAction);
>> 	addAction(m_copy);
>> 	setContextMenuPolicy(Qt::ActionsContextMenu);
>> }
>>
>> And the control never reaches the Item :-
>>
>> void TextRect::contextMenuEvent(QGraphicsSceneContextMenuEvent
>> *contextMenuEvent)
>> {
>> 	//Never comes here :-(
>> }
>>
>> So I dont understand, when does ContextMenuEvent occurs and how is it 
>> propogated to the item :(
>>
>> --Prateek
>>
>> -----Original Message-----
>> From: Stefano Rosellini [mailto:s.rosellini@xxxxxxxxx]
>> Sent: Friday, April 13, 2007 12:28 PM
>> To: QT Mailing LIST
>> Subject: Re: Handling events in Graphics View Framework
>>
>> Have you used 'acceptMouseButtons()' function?
>>
>> Prateek Tiwari ha scritto:
>>   
>>     
>>> Hi,
>>>  
>>> I am not able to understand what is going on in graphics view 
>>> framework relating to event handling.
>>> I tried docs but that didnt really help :-(
>>>  
>>> I have created a contextmenu in QGraphicsView. Now, when I click, 
>>> does
>>>     
>>>       
>>   
>>     
>>> the event go to the GraphicsView or to the Item->scene->view.
>>> I want to handle contextmenu events in the items. There is a function
>>>       
>
>   
>>> provided in QGraphicsItem class
>>>
>>> contextMenuEvent(QGraphicsSceneContextMenuEvent *contextMenuEvent)
>>>
>>> I have reimplemented this function for an Item, but the event never 
>>> reaches here.
>>> I believe I cannt set a context menu for the scene or the 
>>> GraphicsItem
>>>     
>>>       
>>   
>>     
>>> as they are not widgets.
>>> How do I handle the context menu in the items ?
>>>  
>>> Is it also true that I cannot have slots for QGraphicsItem, it gives 
>>> me compile time errors if I declase Q_OBJECT in QGraphicsItem derived
>>>       
>
>   
>>> class..
>>>  
>>> Thnx
>>> Prateek
>>>
>>>  
>>>
>>>     
>>>       
>> --
>> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
>>     
>
>   
>> "unsubscribe" in the subject or the body.
>> List archive and information: http://lists.trolltech.com/qt-interest/
>>
>> --
>> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
>>     
> "unsubscribe" in the subject or the body.
>   
>> List archive and information: http://lists.trolltech.com/qt-interest/
>>
>>   
>>     
>
>
> --
> Dipl.-Ing. Daniel Walz  -  walz@xxxxxxxx
>
> MeVis Technology AG
> Universitaetsallee 29
> 28359 Bremen
> Germany
>
> Trade Registry: Bremen HRB 23791
> Executive Board: Carl J. G. Evertsz (Ph.D.) Head of Supervisory Board:
> Heinz-Otto Peitgen, Ph.D.
>
>   


-- 
 [ signature omitted ] 

Message 8 in thread

Ahh.. I get it now.
So you mean, I should handle the context menu event in the items, then
override the contextmenuevent of the view,
so that events are first captured by the items and then they propogate
to scene and then to view.

And by Setting the contextpolicy I was breaking that flow.

Makes sense now.

Thnx a lot !

--Prateek 

-----Original Message-----
From: Daniel Walz [mailto:walz@xxxxxxxx] 
Sent: Friday, April 13, 2007 4:13 PM
To: QT Mailing LIST
Cc: Prateek Tiwari
Subject: Re: Handling events in Graphics View Framework

Prateek Tiwari schrieb:
> Hey Daniel,
>
> Another thing I notice :-
>
> As you said, if I do not set a contextmenupolicy in the view, the 
> contextmenuevent handler is invoked for the item. But that does not 
> solve the problem. I want to have different contextmenus for items and

> the view.
>   
You can still do that, but you have to override the
contextMenuEvent(...) method, which is called when no item accepted the
event in the first place (any event, that is ignored is propagated to
it's parent, and as a special case from the root-QGraphicsItem to the
QGraphicsView AFAIK.
> Also, I am not able to capture mousePressEvents in the items, whether 
> or not I override them in the View.
>   
That's strange, I never had any trouble with that...
Some things you might want to check:
- check the name and signature of the eventhandler, if you use e.g. 
QMouseEvent* instead of QSceneMouseEvent*
  it is syntactically ok, but will never be called...  happens sometimes
to me...  (use copy and paste for the method name directly from the
doc...)
- you didn't change
http://doc.trolltech.com/4.2/qgraphicsitem.html#setAcceptedMouseButtons
accidently...
- all items being a parent node have
http://doc.trolltech.com/4.2/qgraphicsitem.html#setHandlesChildEvents
set to false.

Hope that helps, good luck

Daniel

> This is driving me nuts and I not see a good documentation that 
> explains the working of QGraphics View Framework.
> The doc by TT isnt that helpful in this case :-(.
>
> Thnx
> Prateek
>
> -----Original Message-----
> From: Daniel Walz [mailto:walz@xxxxxxxx]
> Sent: Friday, April 13, 2007 3:30 PM
> To: QT Mailing LIST
> Cc: Prateek Tiwari
> Subject: Re: Handling events in Graphics View Framework
>
> Hi again,
>
> just a guess, try it without changing the contextMenuPolicy from the 
> default, i think it might change the behaviour for the GraphicsView 
> and therefore for the GraphicsItems.
>
> And also avoid reimplementing contextMenuEvent of your GraphicsView.
>
> But as I said, just a guess...
>
> Good Luck
> Daniel
>
> Prateek Tiwari schrieb:
>   
>> Hi Stefano,
>>
>> All mousebuttons are accepted by default.
>> Also I am able to move the items on the scene, so the mouse events 
>> are
>>     
>
>   
>> accepted.
>>
>> This is how I am setting the contextMenu in the view :-
>>
>> void MyView::createActions()
>> {
>> 	m_addLineAction = new QAction("DrawLine", this);
>> 	bool ret = connect(m_addLineAction,
>> SIGNAL(triggered()),this,SLOT(drawEdge()));
>>
>> 	m_addRectAction = new QAction("DrawRectangle", this);
>> 	connect(m_addRectAction,
>> SIGNAL(triggered()),this,SLOT(drawRect()));
>>
>> 	m_DoNthgAction = new QAction("Draw Nothing", this);
>> 	connect(m_DoNthgAction,
>> SIGNAL(triggered()),this,SLOT(doNthg()));
>>
>> 	m_copy = new QAction("Copy", this);
>> 	
>> }
>>
>> void MyView::createContextMenu()
>> {
>> 	addAction(m_addLineAction);
>> 	addAction(m_addRectAction);
>> 	addAction(m_DoNthgAction);
>> 	addAction(m_copy);
>> 	setContextMenuPolicy(Qt::ActionsContextMenu);
>> }
>>
>> And the control never reaches the Item :-
>>
>> void TextRect::contextMenuEvent(QGraphicsSceneContextMenuEvent
>> *contextMenuEvent)
>> {
>> 	//Never comes here :-(
>> }
>>
>> So I dont understand, when does ContextMenuEvent occurs and how is it

>> propogated to the item :(
>>
>> --Prateek
>>
>> -----Original Message-----
>> From: Stefano Rosellini [mailto:s.rosellini@xxxxxxxxx]
>> Sent: Friday, April 13, 2007 12:28 PM
>> To: QT Mailing LIST
>> Subject: Re: Handling events in Graphics View Framework
>>
>> Have you used 'acceptMouseButtons()' function?
>>
>> Prateek Tiwari ha scritto:
>>   
>>     
>>> Hi,
>>>  
>>> I am not able to understand what is going on in graphics view 
>>> framework relating to event handling.
>>> I tried docs but that didnt really help :-(
>>>  
>>> I have created a contextmenu in QGraphicsView. Now, when I click, 
>>> does
>>>     
>>>       
>>   
>>     
>>> the event go to the GraphicsView or to the Item->scene->view.
>>> I want to handle contextmenu events in the items. There is a 
>>> function
>>>       
>
>   
>>> provided in QGraphicsItem class
>>>
>>> contextMenuEvent(QGraphicsSceneContextMenuEvent *contextMenuEvent)
>>>
>>> I have reimplemented this function for an Item, but the event never 
>>> reaches here.
>>> I believe I cannt set a context menu for the scene or the 
>>> GraphicsItem
>>>     
>>>       
>>   
>>     
>>> as they are not widgets.
>>> How do I handle the context menu in the items ?
>>>  
>>> Is it also true that I cannot have slots for QGraphicsItem, it gives

>>> me compile time errors if I declase Q_OBJECT in QGraphicsItem 
>>> derived
>>>       
>
>   
>>> class..
>>>  
>>> Thnx
>>> Prateek
>>>
>>>  
>>>
>>>     
>>>       
>> --
>> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx 
>> with
>>     
>
>   
>> "unsubscribe" in the subject or the body.
>> List archive and information: http://lists.trolltech.com/qt-interest/
>>
>> --
>> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx 
>> with
>>     
> "unsubscribe" in the subject or the body.
>   
>> List archive and information: http://lists.trolltech.com/qt-interest/
>>
>>   
>>     
>
>
> --
> Dipl.-Ing. Daniel Walz  -  walz@xxxxxxxx
>
> MeVis Technology AG
> Universitaetsallee 29
> 28359 Bremen
> Germany
>
> Trade Registry: Bremen HRB 23791
> Executive Board: Carl J. G. Evertsz (Ph.D.) Head of Supervisory Board:
> Heinz-Otto Peitgen, Ph.D.
>
>   


--
 [ signature omitted ]