Greetings,

premise: I love QML and Qt Quick, and whenever I attempt a Component
design exercise like this, I strive for doing things in the spirit of the
framework, i.e. simple, and declarative.

I tried (not for the first time during my life of Qt Quick user) to make a
(mouse-)interactive component where some item can be resized by mouse.

Inevitably I end up putting a MouseArea as children of an Item that changes
position and/or size, and this will break things, e.g. the mouse
interaction and the dragged items become jittery. I tried various
approaches, e.g. using a MouseArea, a DragHandler, the Drag attached
property. Those all work well when the ancestors are static, but those all
break when any ancestor is interactively moved by mouse.

In hindsight, this probably makes sense, as we are trying to measure
something (e.g. the relative mouse position) while things all around are
moving... it's like building a table during a earthquake :D

I wonder how Qt Quick pros would design a solution to this problem (i.e. it
would be nice to have such a demo amongst the Qt Quick demos ;-) ).

This is how I did it:
https://github.com/fferri/qt-quick-events-timeline/tree/d98b33830291ce9b85670b6bcc41952d513e610b
and if it looks bad to you, consider I tried to solve this or a very
similar problem another 2-3 times in the past 5 years, and this is a great
improvement with respect to my past iterations :-)
In a gist:
- have a "global" MouseArea and a "global" Item used as drag target (global
in the sense their reference frame is never moved interactively by the
mouse)
- have a "local" MouseArea (3 in this case for the 3 regions of an item:
start, middle, end; as dragging over each region has a different function,
i.e.: resizing from left, moving, resizing from right respectively) that
only serves for showing a specific cursorShape, and intercepting the
pressed event (discarding it) to set up the drag target for the global
MouseArea;
- as the global drag target Item moves, the actual item to be moved/resized
watches the changes an computes the adjustments.

It may look extremely hacky and low-level, but it is the only way I could
achieve smooth resizing without the issues mentioned above.

Which makes me wonder if I overlooked something way more obvious to achieve
the same result....

Thanks for any feedback.

Best Regards,
Federico Ferri
_______________________________________________
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest

Reply via email to