简体   繁体   中英

How to acquire the position of QLabel and separate it into x- and y-coordinate variables in PyQt5

I am creating a GUI to drag and drop 5 labels. I want to calculate the distance between any of the two labels by using their x- and y-coordinate of their positions.

I know what with label1.pos() method we can get the position of each label. For example, this is what we may acquire:

PyQt5.QtCore.QPoint(180, 140)

Hence I would like to access the x- and y-coordinate directly in the codes, and use Pythagorean theorem to calculate the distance between them. Do anyone know how to do this?

Your help is much appreciated!

Are you looking for that :

label1.x()
label1.y()

?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM