マウスイベント

2016/09/02

Python2.7.10, PyQt4.11.3

# -*- coding: utf-8 -*-

import sys
from PyQt4 import QtGui,QtCore

class MyWidget(QtGui.QWidget):
    def __init__(self,parent=None):
        super(MyWidget,self).__init__(parent)

    def mousePressEvent(self,event):
        if event.button() == QtCore.Qt.RightButton:
            print('press right button')
        if event.button() == QtCore.Qt.LeftButton:
            print('press left button')

    def mouseDoubleClickEvent(self, event):
            print('double clicked')

    def mouseReleaseEvent(self,event):
        print('mouse release')

    def mouseMoveEvent(self,event):
        print('mouse move')

if __name__ == '__main__':
    app = QtGui.QApplication(sys.argv)
    w = MyWidget()
    w.show()
    sys.exit(app.exec_())