Qt4:操作 QGraphicsItem 时将鼠标光标锁定到位

发布于 2024-08-23 11:05:49 字数 611 浏览 1 评论 0原文

我正在 Qt4 中编写一个使用 QGraphicsScene 的小 GUI 实用程序。当您移动其中一个项目时,它会在水平面上跟踪鼠标,按住修改键可以更改该项目的旋转。旋转项目时,我希望鼠标光标更改为弯曲箭头(或其他东西)并在视觉上锁定到位,因此移动它会影响项目,但不会影响鼠标光标本身。

释放修改器会将(以前不可见的)光标放回其原始点:这是为了防止项目随后“跳”到鼠标的新水平位置,这是我的主要问题。

我真的不知道如何在 Qt4 中实现这一点,而不涉及做一些可怕的事情,例如:

  • 按下修饰符时存储当前鼠标位置
  • 将光标切换到无内容的位图
  • 以某种方式在原始位置绘制一个假光标(!?)
  • 删除假光标并在完成后将鼠标位置切换回来

如果有人能想出更好的方法来实现这一点,我们将不胜感激。我一开始并不太热衷于整个固定鼠标光标的想法,但这是我能想到的解决这个问题的唯一方法,使用控制方案,否则效果很好。

编辑:我尝试了上面概述的垃圾方案,但在以编程方式移动鼠标位置时遇到了问题。仍然试图记住我以前在哪里使用过类似的系统:基本上它是一个旋钮。单击它并上下移动鼠标,从而旋转旋钮。当您释放鼠标按钮时,指针回到您最初放置的位置,即旋钮上。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

薯片软お妹 2024-08-30 11:05:49

当这种情况发生时,使用事件过滤器来捕获 QMouseEvents 怎么样?

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文