PDA

View Full Version : contextMenuEvent



mickey
29th May 2006, 13:22
Hi, I implemeted this below to have a mouse menu; problem: when I click and move mouse and then release, menu appear; If I click and move I traslate the scene; and when I release mouse, i don't want menu mouse appear; how this? (is there a QT way?) thanks


void MyWidget::contextMenuEvent(QContextMenuEvent* event)

mickey
29th May 2006, 23:30
Anyone know this?

wysota
30th May 2006, 00:27
Could you explain what the exact problem is? What you expect and what you get?

mickey
30th May 2006, 00:53
The problem is this: if I click right mouse contextMenuEvent is called and a popupmousemenu is drawn; problem is if I press mouse dx and move mouse my scene will be rotate; after this, when I release mouse, contextMenuEvent is called: and this isn't right; mouse menu have to be drawn only if I click (in a point) and release immediately (without move).are u understand?

jpn
30th May 2006, 07:06
Catch mouse button press/release events, compare press/release offset, show the context menu only if the offset was in allowed range.

wysota
30th May 2006, 09:42
As far as I know the context menu on Windows is shown upon release of the button (at least in Qt4). Do you receive the event after pressing the button?

How does your menu event handler look like?

jpn
30th May 2006, 10:11
wysota, yep, release event comes before the context menu event. As far as I understood correctly, he wants to avoid showing of context menu if mouse was moved during press and release.

mickey, the context menu event is sent regardless of that if the mouse was moved or not. You will have to examine the possible movement manually.

wysota
30th May 2006, 12:26
I think you should just ignore the event based on the geometry, content or simply previous mouse events.

mickey
30th May 2006, 15:11
event is called when I release mouse! But If I pressed dx button for do traslation, menu mustn't appear!

jpn
30th May 2006, 15:42
event is called when I release mouse! But If I pressed dx button for do traslation, menu mustn't appear!
Yes, we understood the problem. Here's a couple of pseudo algorithms to solve it. The choice is yours:


mousePressEvent:
pressPoint = mouse press event's position

contextMenuEvent:
if distance between context menu event's position and pressPoint is less than something
show context menu
else do nothing

or


mousePressEvent:
pressPoint = mouse press event's position

mouseReleaseEvent:
if distance between mouse release event's position and pressPoint is less than something
showContextMenu = true
else
showContextMenu = false

contextMenuEvent:
if showContextMenu
show context menu
else do nothing

or


mousePressEvent:
showContextMenu = true

mouseMoveEvent:
showContextMenu = false

contextMenuEvent:
if showContextMenu
show context menu
else do nothing

or ....

wysota
30th May 2006, 16:10
Hmm... could you provide a minimal compilable example which reproduces the problem? Because as for now we're talking about a bit abstract behaviour.

mickey
30th May 2006, 16:48
i think so long...but Do I have use some flag to do this?when right mouse button do some things (translate, change color of scene where I pick (only if I have a pushbutton down). so if traslate or changing color (it works), when I releae mouse appear menu; I can follow advice of jpn (for every things I set a flags menuContext=false), but I hoped find a Qt way....such as ignore() (but I haven't idea how use it):..

wysota
30th May 2006, 18:04
If you do, remember to reimplement also the release event to clear values which were set in previous handlers.

mickey
3rd June 2006, 15:14
I'm trying this; with mouseMoving flag it works; but I wonder how use ignore() function


void MyWidget::contextMenuEvent(QContextMenuEvent* e) {
if (mouseMoving) {mouseMoving = false; return;}
//if (mouseMoving) e->ignore(); //Must I use ignore() in that way?

Where do I have to use ignore? and how cal it? thanks