Why do I have trouble changing mouse cursors in my implementation of an interactive QGraphicsView in Qt?

别说谁变了你拦得住时间么 提交于 2019-12-06 15:31:58

I have created a similar image manipulation application some months ago: image drag, zoom-in/out + different custom tools to draw (add) specific items on a QGraphicsView. I used only the setCursor() function - not the unsetCursor().

I created a timer and I set the cursor-shape inside the timer-event function according to a custom "Tool-Type" flag stored in my GraphicsView subclass and taking into account the current state of keyboard & mouse. I think this is more convenient as:

a) It allows you to set the cursor-shape even if the user does not move the mouse or click on a specific object - e.g. if a "zoom tool" is selected you can set the cursor to a (+) [zoom-in cursor]. If the user holds-down the Ctrl-Key you can set the cursor to a (-) [zoom-out cursor]

b) There is no need to store any cursor states: You just set the correct cursor-shape according to currently selected tool and the mouse/keyboard state.

c) It's the easiest way to make your cursor-shape to quickly respond to all keyboard/mouse/tool-change events

I hope this timer idea can help you to overcome all cursor-shape related problems. A timer with a 30 msec interval it will be just fine.

Looks like you hit this bug:

https://bugreports.qt-project.org/browse/QTBUG-4190

Workaround is to set the cursor on the view rather than the item

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!