该楼层疑似违规已被系统折叠隐藏此楼查看此楼
from PyQt4.QtGui import *
from PyQt4.Qt import *
from PyQt4.QtCore import *
import sys
#第一种,自定义控件,使用重新实现特定事件处理器,派生一个组件,重新实现它的事件处理,主要使用mousePressEvent、mouseReleaseEvent以及mouseMoveEvent这三个事件处理
class MyBuuton(QPushButton):
def __init__(self,parent=None):
super(MyBuuton,self).__init__(parent)
def mousePressEvent(self,event):
self.setText(QString(*x:%1,y:%2*).arg(QString.number(event.x())).arg(QString.number(event.y())))
def mouseReleaseEvent(self, event):
self.setText(QString(*x:%1,y:%2*).arg(QString.number(event.x())).arg(QString.number(event.y())))
def mouseMoveEvent(self, event):
self.setText(QString(*x:%1,y:%2*).arg(QString.number(event.x())).arg(QString.number(event.y())))
def event(self, e):#看下&&
if e.type()==QEvent.MouseButtonPress:
event=MyBuuton(e)
self.setText(QString(*x:%1,y:%2*).arg(QString.number(event.x())).arg(QString.number(event.y())))
return True
elif e.type()==QEvent.MouseButtonPress or e.type()==QEvent.MouseMove:#屏蔽MouseButtonRelease和MouseMove事件
return True
return QPushButton.event(e)#其他事件调用基类的event()函数进行处理
QTextCodec.setCodecForTr(QTextCodec.codecForName(*utf-8*))
app =QApplication(sys.argv)
x = MyBuuton()
x.setWindowTitle(u*处理器*)
x.resize(400,200)
x.show()
app.exec_()
显示错误:
return QPushButton.event(e)#其他事件调用基类的event()函数进行处理
TypeError: QPushButton.event(QEvent): first argument of unbound method must have type *QPushButton*
学习地方:/venow/archive//10/10/2718019.html