views:

241

answers:

1

I'm writing a little GUI utility in Qt4 which uses a QGraphicsScene. One of the items tracks the mouse in the horizontal plane as you move it around, and holding down a modifier key allows you to change the item's rotation. When rotating items I'd like the mouse cursor to change to a curvy arrow (or something) and lock visually in place, so moving it affects the item but not the mouse cursor itself.

Releasing the modifier would place the (previously invisible) cursor back to it's original point: this is to prevent the item "jumping" to the mouse's new horizontal position afterwards, which is my main problem.

I've really got no idea how to implement this in Qt4 that doesn't involve doing horrible things like:

  • When the modifier is pressed store the current mouse position
  • Switch the cursor to a bitmap of nothing
  • Somehow draw a fake cursor in the original place (!?)
  • Delete the fake cursor and switch the mouse position back when done

Be very grateful if anyone can think of a better way to achieve this. I'm not too wedded to the whole fixed mouse cursor idea in the first place but it's the only way I can think to get around this one problem with a control scheme that otherwise works pretty nicely.

Edit: I tried the crap scheme I outlined above and ran into problems moving the position of the mouse programmatically. Still trying to remember where I've used a similar system before: basically it was a rotary knob. You clicked it and moved the mouse up and down, which rotated the knob. When you released the mouse button the pointer was back where you'd initially put it, on the knob.

+1  A: 

How about using an event filter to catch QMouseEvents, while this is going on?

Karol Wilk
Thanks very much for the useful suggestion. I looked it up and the event filter looks like the best way to go here (and for a lot of other stuff - I've never used them before.)I did try implementing the (horrible) method I outlined but ran into weird problems trying to manipulate the actual mouse pointer (as opposed to cursor) position, and eventually abandoned it for a very different scheme which has a similarly bad code smell.
Mikesname
BTW, I'm sure I've seen the fixed cursor thing in action on Windows for, e.g. moving virtual knobs on software synthesizers and the like, so I'd still be interested in knowing how you do this.
Mikesname