PDA

View Full Version : restricting mouse move



wagmare
28th March 2012, 10:28
Hi friends,

Is it possible to move the mouse cursor only in a particular region of a graphicsview or scene . i just want to restrict the mouse move only in specific rectangular region.
currently i tried eventFilter but is there any other way ...


Thanks & Regards,
Wagmare

wysota
28th March 2012, 11:07
Do you want to restrict the physical cursor or received mouse events? In other words, what do you need it for?

wagmare
28th March 2012, 13:43
Thanks for reply ...
this is my requirement ... im having a window (graphicsView) with an ellipse or circle at the center which covers the 70% of the region and remaining portions im having some buttons at right and bottom side of the window.
my task is
when user clicks a button i have to move the cursor to that ellipse region and the mouse move should be within that ellipse bounding region..

Thanks once region ..

wysota
28th March 2012, 14:18
That doesn't really answer my question :) Do you want to restrict the physical cursor pointer (I don't think Qt can do that) or mouse events you're getting from the widget (Graphics View can do that)? If the requirement is to force the user to choose some point from within a restricted area then restricting events should be enough.

wagmare
29th March 2012, 09:45
Once again thanks for the reply ..
i want to restrict the events into the particular area ... inside an ellipse area ...

Thanks

wysota
29th March 2012, 12:08
In that case basically you have two options, both involving QGraphicsItem::itemChange(). If you have an item which you want to restrict to a certain area then reimplement itemChange() for that item and monitor QGraphicsItem::ItemPositionChange changes to see whether the items wants to be placed outside your area of interest and prevent that by returning a position from inside that area. If you don't have an item but rather want to force a user to click within the area then hide the mouse pointer (by setting it to a blank shape), create a dedicated item that will serve as a cursor, optionally grab the mouse to that shape and then use itemChange() like I described earlier.

wagmare
29th March 2012, 13:43
Im going to use ur second option ... thanks !!

wysota
29th March 2012, 13:52
Oh, and of course enable mouse tracking.