Hello sorry for my newbie question but i tried quite a lot of ways to solve it.. I wonder how can i get the coordinate of my cursor with my left mouse button click. I tried QMouseEvent but seems like i have difficulties calling and defining it. I want to get the cursor x and y coordinate on script shell after clicking my left mouse button. QCursor.pos () seems working but i want to get coordinates on my drawing panel and with my mouse button.
In other words, i want the bottom coordinate panel of QCad be displayed on my script shell output with my mouse click. (the attachment picture shows that panel)
Which function should i use and how can i call it?
Thanks a lot.
Getting cursor coordinate with mouse click
Moderator: andrew
Forum rules
Always indicate your operating system and QCAD version.
Attach drawing files and screenshots.
Post one question per topic.
Always indicate your operating system and QCAD version.
Attach drawing files and screenshots.
Post one question per topic.
Getting cursor coordinate with mouse click
- Attachments
-
- 1.png (7.68 KiB) Viewed 2416 times
Re: Getting cursor coordinate with mouse click
If your script needs to interact with the user, you would typically write a script action (see examples in scripts) and not use the script shell. Script actions are receiving mouse move events, mouse click events, etc.
To get the current position of the mouse cursor in the script shell:
To get the current position of the mouse cursor in the script shell:
Code: Select all
// get the graphics view widget:
view = getGraphicsView()
// get mouse cursor position in pixel (relative to the top left corner of the widget):
posPixel = view.mapFromGlobal(QCursor.pos());
// map to coordinate
posCoord = view.mapFromView(new RVector(posPixel.x(), posPixel.y()))