반응형
PyQt5 -- 마우스 event 사용 예제
환경 ;
참고 ; http://penguinitis.g1.xrea.com/computer/programming/Python/PyQt5/PyQt5-memo/PyQt5-memo.html
http://doc.qt.io/qt-5/qmouseevent.html
http://doc.qt.io/qt-5/qwheelevent.html
< 실행 결과 >
< 소스 >
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from PyQt5.QtWidgets import QMainWindow, QApplication, QDesktopWidget | |
| from PyQt5.QtCore import Qt | |
| class Main(QMainWindow): | |
| def __init__(self): | |
| super().__init__() | |
| self.setMouseTracking(True) | |
| self.setWindowTitle('mouse') | |
| self.resize(320, 240) | |
| self.show() | |
| def mouseButtonKind(self, buttons): | |
| if buttons & Qt.LeftButton: | |
| print('LEFT') | |
| if buttons & Qt.MidButton: | |
| print('MIDDLE') | |
| if buttons & Qt.RightButton: | |
| print('RIGHT') | |
| def mousePressEvent(self, e): # e ; QMouseEvent | |
| print('BUTTON PRESS') | |
| self.mouseButtonKind(e.buttons()) | |
| def mouseReleaseEvent(self, e): # e ; QMouseEvent | |
| print('BUTTON RELEASE') | |
| self.mouseButtonKind(e.buttons()) | |
| def wheelEvent(self, e): # e ; QWheelEvent | |
| print('wheel') | |
| print('(%d %d)' % (e.angleDelta().x(), e.angleDelta().y())) | |
| def mouseMoveEvent(self, e): # e ; QMouseEvent | |
| print('(%d %d)' % (e.x(), e.y())) | |
| if __name__ == '__main__': | |
| import sys | |
| app = QApplication(sys.argv) | |
| win = Main() | |
| sys.exit(app.exec_()) |
---
반응형
'PyQt5' 카테고리의 다른 글
| PyQt5 -- menu 만들기, QAction 사용 (0) | 2017.05.02 |
|---|---|
| PyQt5 -- 키보드 event 사용 예제 (0) | 2017.05.02 |
| PyQt5 -- 마우스 event & 마우스 현재 위치 출력하기 (0) | 2017.05.01 |
| PyQt5 -- custom data-carrying signal & slot 만들기 예제 (0) | 2017.05.01 |
| PyQt5 -- signal & slot 예제 (0) | 2017.05.01 |


