我尝试将鼠标事件添加到一个新的QAction对象中。我想在自定义菜单中使用它们from PyQt4 import QtCore, QtGui
from PyQt4.QtCore import QEvent, pyqtSignal as Signal, pyqtSlot as Slot
class MouseEvent(QEvent):
def __init__(self):
super(MouseEvent,self).__init__(QEvent.Type(QEvent.MouseButtonRelease))
class MyAction(QtGui.QAction):
clicked = Signal()
def __init__(self, name, parent):
super(MyAction, self).__init__(name, parent)
self.customEvent(MouseEvent)
def mousePressEvent(self, event):
if event.button() == QtCore.Qt.RightButton:
event.accept()
self.clicked.emit()
self.rightClicked(event)
else:
event.ignore()
@Slot()
def rightClicked(self, event):
print "right clicked"
return event
class AnyApplication(QtGui.QMainWindow):
def __init__(self):
super(AnyApplication,