[Interest] QtLocation MapPolyLine and MouseArea
maitai
maitai at virtual-winds.org
Fri Mar 8 09:09:25 CET 2019
And indeed that was it!
In the MapPolyLine's MouseArea I just replaced "anchor.fill: parent"
with "containmentMask: polyline" and (luckily I think) it works without
any further calculations.
Thanks a lot for the tip.
Philippe.
Le 08-03-2019 08:18, maitai a écrit :
> Thanks Shawn, that looks the best approach, I 'll give it a try.
>
> Le 07-03-2019 20:29, Shawn Rutledge a écrit :
>>> On 7 Mar 2019, at 18:32, maitai <maitai at virtual-winds.org> wrote:
>>>
>>> Hi,
>>>
>>> I need to trigger various actions whenever a MapPolyLine is hovered
>>> or pressed, such as displaying a tooltip, a menu, etc.
>>>
>>> I have put a MouseArea on it with anchors.fills: parent, but the
>>> problem is that the mouse area does not represent the line, but the
>>> polygon made by the line. For instance if you have a L shape, entered
>>> event and so on is triggered when you enter the bounding rectangle of
>>> the line, not when you hover over the line itself.
>>>
>>> On a QGraphicsScene we had the shape() protected method for that
>>> kinds of case, for instance with a QPainterPathStroker to give some
>>> thickness to the line's "mousearea".
>>>
>>> I will probably end with a custom property that will carry the pixel
>>> distance between the line segments and the mouse coordinates, but
>>> this is going to be heavy to compute (I have potentially hundreds of
>>> complicated lines on the map).
>>>
>>> Is there a better way or even better a standard way to do that?
>>
>> Check out containmentMask: that’s how you can redefine the behavior of
>> MouseArea’s contains() method in QML.
>>
>> You could use HoverHandler and/or TapHandler though, and then perhaps
>> set containmentMask on the polyline itself if behavior is still not
>> what you want (I haven’t tried it with MapPolyLine myself, only with
>> QtQuick.Shapes).
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> https://lists.qt-project.org/listinfo/interest
More information about the Interest
mailing list