繁体   English   中英

如何只在Qlabel中获取鼠标position? (对于 pyqt5)

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

如何只在Qlabel中获取鼠标position? 我希望鼠标 position 在 qlabel 中启动。 所以: qlabel循环

我的代码

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

我不知道在你的情况下self代表什么,但如果它是小部件或 window 包含 label,正如我假设的那样,那么你可以使用这个坐标转换:

labelPos = self.ui.labelLOOPVIDEO.mapFrom(self, event.pos())
x = labelPos.x()
y = labelPos.y()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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