Here’s my take on it, see if it helps:
I created an array to store the coordinates of where in the widget the mouse clicks: Points
I’ve overridden OnMouseButtonDown and add a 2d coordinate to the aforementioned Points array whenever the user clicks with the *LeftMouseButton *only.
And here’s the OnPaint:
DrawLines handles all the lines for the generated points and an additional DrawLine draws a line from the last element of the Points array to the mouse position on the screen.
If you want to detect clicks on the entire canvas, set its Visibility to Visible. Here I’ve placed a border which is the only Visible element so the clicks outside do not register.
This is by no means perfect but should get you started, good luck!