[Solved] Paint order / Clipping?
hope someone can help me with the following problem:
- one big rectangle as a background
- two rectangles "left" and "right" side by side on top of the first rectangle
- some smaller "drag"-rectangles on top of the left rectangle. These small rectangles should be
moved by drag-and-drop to the right side rectangle.
the small "drag"-rectangles are only visible if they are moved on top of the left- or background-rectangle. If I move it on top of the right-rectangle it gets invisible and is painted behind the right rectangle.
I think it has nothing to do with z-ordering. I tried to give the small rects big z-values but without any effect.
Do I have to dynamically reparent the moved rectangle?
How can this be done?
Many thanks in advance.
Do you have to have the draggable rectangle as a child of the left rectangle?
If you just put the left right and drag rectangle all as direct children of your "big" rectangle it would work.
If you have to have the draggable rect as a child of the left or right you can reparent it by reassigning the parent property to the id of the right rectangle.
@dragRectId.parent = rightId@
How you do that might be tricky if you try to use the mouse position since positioning is relative to the parent. I just did a quick test with a draggable rectangle and a key handler. When I hit the key I reparent to the right rectangle.
<shameless plug> I cover doing dynamic adjustment to the color property of a dragged rectangle in my Qt Quick Fundamentals course on Pluralsight which just went live this week. Very similar to what you're after.</shameless plug>
thanks for your answer. It already helped a little bit. I think I have to do the reparenting. Maybe the onEntered-handler of a DropArea is a suitable place for this. I will try it out.
But one thing is strange: When I want to move an item around by dragging it with the mouse, I don't want that it is obscurred by other items of a scene. As long as the moving is active it should always be visible on top of all other items. Is there a way to implement such a behaviour? Do I have to temporarily reparent the item to a global root? Is there a global root?
The "drag and drop example code":http://qt-project.org/doc/qt-5/qtquick-draganddrop-example.html should do what you want. Look for how they use states and the ParentChange object to re-parent the drag item to the root while it's being dragged.
If this doesn't work, either post some code or specify what you're doing differently that doesn't work.
Ok. This works now. As long as the drag is active I have to reparent the dragged rect to something global (I introduced a global background rect for that purpose).
Thanks for the help.