How to move a QGraphicsItem to another scene without losing the mouse grab?
I have one QGraphicsScene
as the main scene with several movable QGraphicsItem
s in it and another QGraphicsScene
on top of the main scene as an overlay. The overlay scene is exactly the same size as the user's display, whereas the main scene is much bigger, so it needs to be scrolled up and down automatically.
If an item in the main scene is going to be moved, I want to remove that item from the main scene and add it to the overlay scene, let the user move the item in the overlay scene, and as soon as the mouse is released put it back to the main scene. This allows me to smoothly auto scroll the main scene when the item approaches to the edges of the display.
The problem is the following; when an item is removed from its scene, it receives an QMouseUngrab开发者_开发技巧
event, so it is not possible to continue moving the item without clicking it again in the overlay scene. I have tried to prevent the ungrab event or generate a fake QMousePress
in the overlayscene, however none of them solved the issue.
Do you have an idea how I can start moving an item in one scene and continue moving it in another scene without any break?
In other words:
QMousePress
happens in the main scene- Several
QMouseMove
s and finally aQMouseRelease
should happen in the overlay scene - Right after
QMouseRelease
the item will be put back to the main scene
What you may need to do is use the drag and drop framework. You can start a system drag when the mouse leaves the initial canvas, and then as long as your overlay scene accepts the mime data you've packed into your QDrag, the two can inter-operate.
It's a somewhat frustrating system, since it provides the least-common-denominator functionality on all platforms. But it will allow you communicate between the two widgets in a single operation.
精彩评论