|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
我重写了一个QLabel,但是想把坐标返回给其它函数使用,return e.pos().x(),e.pos().y() 会报错,如果在这里进行坐标值的判断后返回1,2,3,4的int型数值就可以实现,但我希望可以统一返回坐标在其它类/函数内进行处理,应该怎么做呢?
class MyLabel(QLabel):
global i,x,y
def __init__(self,parent=None):
super(MyLabel, self).__init__(parent)
self.if_mouse_press = False
def mouseMoveEvent(self, e):
#print ('mouse move:(%d,%d)\n'%(e.pos().x(),e.pos().y())) #获取鼠标坐标
if self.if_mouse_press:
print('mouseMoveEvent')
def mousePressEvent(self, e):
#print ('mousePressEvent(%d,%d)\n'%(e.pos().x(),e.pos().y()))
self.if_mouse_press = True
x,y=e.pos().x(),e.pos().y()
return e.pos().x(),e.pos().y()
# if 10 < e.pos().x() < 335 and 10 < e.pos().y() < 255:
# i = 1
# if 340 < e.pos().x() < 665 and 10 < e.pos().y() < 255:
# i = 2
# if 10 < e.pos().x() < 335 and 260 < e.pos().y() < 505:
# i = 3
# if 340 < e.pos().x() < 665 and 260 < e.pos().y() < 505:
# i = 4
def mouseReleaseEvent(self, e):
#print ('mouseReleaseEvent(%d,%d)\n'%(e.pos().x(),e.pos().y()))
self.if_mouse_press = False
|
|