简体   繁体   中英

How to get mouse position only in Qlabel? (for pyqt5)

How to get mouse position only in Qlabel? I want mouse position to start in qlabel. So: qlabel loop

my code

def mousePressEvent(self, event):
    ret = self.hasMouseTracking()  # Back to mouse MouseTracking The state of
    self.ui.labelLOOPVIDEO.setText(' The mouse moved :%s' % ret)
    x = event.x()
    y = event.y()
    self.ui.labelLOOPVIDEO.setText(' mouse x coordinate :%s  , mouse y coordinate :%s' % (x, y))

I do not know what self represents in your case, but if it is the widget or window which contains the label, as I assume, then you can use this coordinate transformation:

labelPos = self.ui.labelLOOPVIDEO.mapFrom(self, event.pos())
x = labelPos.x()
y = labelPos.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