¾È±Ô °øºÎ¹æ

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)

  -- ¸¶¿ì½º ÈÙÀ» µ¹·ÈÀ»¶§ È£ÃâµÇ´Â ¸Þ¼­µå.

 
¡Ø Ȥ½Ã µµ¿òÀÌ µÇ¼Ì´Ù¸é ´ñ±Û¿¡ ÇѸ¶µð ³²°ÜÁÖ¼¼¿ä!
ÀÛ¼ºÀÚ   ºñ¹Ð¹øÈ£
ÀÚµ¿±Û ¹æÁö     (ÀÚµ¿±Û ¹æÁö ±â´ÉÀÔ´Ï´Ù.)
³»¿ë   ´ñ±Û´Þ±â 
À̸ÞÀÏ ¹®ÀÇ : cak0280@nate.com  
Copyright 2000 By ENTERSOFT.KR All Rights Reserved.