鱼C论坛

 找回密码
 立即注册
查看: 1762|回复: 4

重写pyqt5的QLabel后返回坐标出错

[复制链接]
发表于 2019-9-17 11:22:59 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

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
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2019-9-17 11:32:16 | 显示全部楼层
报什么错误来着,好久没用pyqt了
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-9-17 11:44:04 | 显示全部楼层
塔利班 发表于 2019-9-17 11:32
报什么错误来着,好久没用pyqt了

Process finished with exit code -1073740791 (0xC0000409)
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-9-17 11:54:03 | 显示全部楼层
应该是返回相对于控件的坐标吧,你这没控件所以没有返回值吧。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-9-17 12:25:05 | 显示全部楼层
niuthon 发表于 2019-9-17 11:44
Process finished with exit code -1073740791 (0xC0000409)

看外观是没大问题,pyqt会把好多错误规避,这一般看你怎么放置这个LABEL到窗口,窗口又是怎么运行的
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2026-1-19 08:45

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表