[Interest] Qt Quick and interactive components with moving MouseAreas

Federico Ferri federico.ferri.it at gmail.com
Mon Apr 1 15:29:53 CEST 2024


On Fri, 29 Mar 2024 at 18:15, Federico Ferri <federico.ferri.it at gmail.com>
wrote:

> 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.
>

I realized that approach fails short as soon as one wants to handle
additional events (e.g. click) on the resizable item.
So I changed that to:

https://github.com/fferri/qt-quick-events-timeline/blob/6c99428bb99b869049204f365db36981767d2f4a/EventsTimeline.qml

i.e.:
 - the draggable area (MouseArea within dummy Item, id
'eventDragAreaComponent') is detached from its parent as soon as it loads,
and turned into a sibling of the actual item to be resized (to avoid the
drag "earthquake").
 - the item to be resized watches for geometry changes in that draggable
area, and computes the changes accordingly.

less hacks, but still requires some boilerplate to manage the geometry of
those draggable areas, e.g. place them after a drag operation has finished,
computing the change during the drag....
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20240401/a950d4a2/attachment.htm>


More information about the Interest mailing list