Perl Monk, Perl Meditation | |
PerlMonks |
[OT] QML Canvas Context2D and mouse inputby afoken (Chancellor) |
on Jan 23, 2023 at 16:31 UTC ( [id://11149792]=perlquestion: print w/replies, xml ) | Need Help?? |
afoken has asked for the wisdom of the Perl Monks concerning the following question: So, I'm once again stuck with a legacy version of QML from Qt 5, Qt 5.9.6 to be exact. I need to draw a kind of interactive "map" on a touch screen. The map has tens of irregularly shaped areas that ...
The map comes as an SVG file, but I will probably convert it to Javascript code painting on a Canvas object. That solves at least my coloring and labeling problems and leaves only the mouse input problem. Each area needs its own event handler, and clicking on the map background needs to be ignored. I can only put a single MouseArea into the Canvas, and from its onClicked handler, I need to find the area from the mouse coordinates. There is a method Context2D.isPointInPath(x,y) which looks promising. It works fine if I have just a single area. Adding a second area returns the same, modified object, and so testing mouse coordinates always reports a mouse click on both areas when clicking the second one, and no hit when clicking on the first one. Obviously, I'm doing something wrong. This is my ugly proof-of-concept test code, with just two square areas on a square map:
Of couse, If I had Qt 5.15 available, I would use Shape and PathSvg, and put MouseAreas into the individual Shapes. But all I have is Qt 5.9.6, Shape was introduced in 5.10. Any hints? Alexander
-- Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
Back to
Seekers of Perl Wisdom
|
|