Getting cursor coordinate with mouse click

Use this forum to ask questions about how to do things in QCAD.

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Attach drawing files and screenshots.

Post one question per topic.

Post Reply
woddy
Junior Member
Posts: 13
Joined: Mon Mar 05, 2018 10:44 pm

Getting cursor coordinate with mouse click

Post by woddy » Mon Mar 05, 2018 10:57 pm

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.
Attachments
1.png
1.png (7.68 KiB) Viewed 2397 times

User avatar
andrew
Site Admin
Posts: 9019
Joined: Fri Mar 30, 2007 6:07 am

Re: Getting cursor coordinate with mouse click

Post by andrew » Tue Mar 06, 2018 10:01 am

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:

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()))

Post Reply

Return to “QCAD 'How Do I' Questions”