记录PyQt5 学习中遇到的一些问题
1 信号与槽的设置中,槽函数不用写括号:
btn.clicked.connect(cao())
def cao():
********
会报错:argument 1 has unexpected type 'NoneType'
应写成: btn.clicked.connect(cao)
2 重写类继承父类的__inti__时:
1 class myWindows(QtWidgets.QWidget): 2 def __init__(self): 3 supper().__init__() 4 self.resize(200,200) 5 ......... 6 7 # 以上写法是正确的,或者 8 class myWindows(QtWidgets.QWidget): 9 def __init__(self,*args,**kwargs: 10 supper().__init__(*args,**kwargs) 11 self.resize(200,200) 12 ......... 13 *这样也是正确的 14 15 如果用自动补全的supper会报错: 16 supper(myWindows,self).__init__()
3 设置鼠标位置时
setPos(x,y)时,x和y是指的全局坐标(屏幕),怎么设置成本地或控件内的坐标呢?好像没有对应的方法;
我的方法是将x,y换算成窗口的坐标:
1 def mouseMoveEvent(self, ms): 2 wincu=self.cursor() 3 4 mx=random.randint(self.x(),self.x()+self.width()) 5 my=random.randint(self.y(),self.y()+self.width()) 6 wincu.setPos(mx,my)
缺点是窗口移动后就不生效了

浙公网安备 33010602011771号