Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python PyQt: how to get mouse position x and y

I’m trying to get the x and y position from a QCursor variable

def run(self):
   pos = QCursor.pos()
   print(pos.toPoint())

this prints the following:

PyQt6.QtCore.QPoint(523, 590)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

if i try to print pos.x or pos.y it prints the following:

<built-in method x of QPoint object at 0x7fe85027b0b0

When i googled i found out the mapFromGlobal() method, but i couldn’t make it work.
Is there any way to get X and Y values?

thanks

>Solution :

pos.x and pos.y are methods, not properties so they need to be called.

try:

pos.x()
pos.y()

Anytime you print an object in python and it looks like <built-in method ... that means the attribute is a method and needs to be invoked.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading