pyqt+python自定义信号

#代码如下:
import sys
	 
from PyQt4 import QtCore, QtGui, QtWebKit

class MyWebView(QtWebKit.QWebView):
   def __init__(self, parent = None):
      QtWebKit.QWebView.__init__(self, parent)

      self.connect(self, QtCore.SIGNAL('rightClick'), self.showMenu)#连接信号槽
     
   def mousePressEvent(self, event):#触发信号的事件
      if event.button()==QtCore.Qt.RightButton:#单击鼠标右键时触发信息
         self.emit(QtCore.SIGNAL('rightClick'))

   def showMenu(self):#对应的槽,即信号触发后的处理函数
      QtGui.QMessageBox.about(self, 'message',str('dqad'))

app = QtGui.QApplication(sys.argv)
qb = MyWebView()
qb.show()
sys.exit(app.exec_())

参考来源:

http://blog.csdn.net/adream307/article/details/6312074

http://huqilong.blog.51cto.com/53638/274046

http://www.360doc.com/content/13/0129/17/9934052_263087286.shtml

你可能感兴趣的:(PYQT)