English 中文(简体)
Qt4: Locking the mouse cursor in place while manipulating QGraphicsItem
原标题:

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.

最佳回答

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

问题回答

暂无回答




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签