Python ÇÁ·Î±×·¡¹Ö > PyQt5 - ¸¶¿ì½º °ü·Ã À̺¥Æ® ¿¹Á¦
µî·ÏÀÏ : 2017-11-14 19:29
Á¶È¸¼ö : 56,462
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 mousePressEvent(self, event): #event : QMouseEvent
if event.buttons() & Qt.LeftButton:
print('BUTTON PRESS - LEFT')
if event.buttons() & Qt.MidButton:
print('BUTTON PRESS - MIDDLE')
if event.buttons() & Qt.RightButton:
print('BUTTON PRESS - RIGHT')
def mouseReleaseEvent(self, event): # event : QMouseEvent
print('BUTTON RELEASE')
def wheelEvent(self, event): # event QWheelEvent
print('wheel')
print('(%d %d)' % (event.angleDelta().x(), event.angleDelta().y()))
def mouseMoveEvent(self, event): # event QMouseEvent
print('(%d %d)' % (event.x(), event.y()))
if __name__ == '__main__':
import sys
app = QApplication(sys.argv)
win = Main()
sys.exit(app.exec_())
1. setMouseTracking()
-- False °ª ¼³Á¤½Ã¿¡´Â, ¸¶¿ì½º Ŭ¸¯½Ã¿¡¸¸ ¸¶¿ì½º À̵¿ °¨Áö.
-- True ¼³Á¤½Ã¿¡´Â, ¸¶¼ö½º Ŭ¸¯ ¾ÈÇصµ ¸¶¿ì½º À̵¿ °¨Áø.
2. mousePressEvent(event)
-- ¸¶¿ì½º ¹öÆ°À» Ŭ¸¯ÇÒ ¶§ È£Ã⠵Ǵ ¸Þ¼µå.
3. mouseMoveEvent(event)
-- ¸¶¿ì½º°¡ ¿òÁ÷À϶§ È£ÃâµÇ´Â ¸Þ¼µå.
--event.x, event.y() : widget ³»ÀÇ ¸¶¿ì½º ÁÂÇ¥
-- event.globalX(), event.globalY() : ȸ鳻ÀÇ ¸¶¿ì½º ÁÂÇ¥
4. mouseReleaseEvent(event)
-- ¸¶¿ì½º ¹öÆ°À» Ŭ¸¯ÇÑ ÈÄ ¶¼¾úÀ»¶§ È£ÃâµÇ´Â ¸Þ¼µå.
5. wheelEvent(event)
-- ¸¶¿ì½º ÈÙÀ» µ¹·ÈÀ»¶§ È£ÃâµÇ´Â ¸Þ¼µå.