python自定义事件event_PyQt:如何使用自定义事件创建自定义QAction

我尝试将鼠标事件添加到一个新的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, self).__init__()

self.UI()

def UI(self):

menuBar = self.menuBar()

m = menuBar.addMenu("Edit")

a = MyAction("Do", m)

#a.clicked.connect(self.doMoreWithClicked)

m.addAction(a)

def doMorWithClicked(self):

print "Do more.."

app = QtGui.QApplication(sys.argv)

anyApp = AnyApplication()

anyApp.show()

sys.exit(app.exec_())

我得到以下错误:

^{pr2}$

我真的很想了解我是如何创建自己的事件,并将它们与信号和时隙相结合。在

谢谢。。。在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值