当前位置:   article > 正文

PyQt5 鼠标事件_qt mousegrabber

qt mousegrabber

1、继承 QWidget 

2、事件捕获

  1. from PyQt5.QtCore import Qt
  2. from PyQt5.QtWidgets import QWidget
  3. from py_ui.demo import Ui_demo
  4. class handler_demo(QWidget, Ui_demo):
  5. def __init__(self):
  6. super().__init__()
  7. self.setupUi(self)
  8. def mousePressEvent(self, e):
  9. if e.button() == Qt.RightButton:
  10. self.input1.setText("RightButton press")
  11. elif e.button() == Qt.LeftButton:
  12. self.input1.setText("LeftButton press")
  13. elif e.button() == Qt.BackButton:
  14. self.input1.setText("BackButton press")
  15. elif e.button() == Qt.ForwardButton:
  16. self.input1.setText("ForwardButton press")
  17. elif e.button() == Qt.MiddleButton:
  18. self.input1.setText("MiddleButton press")
  19. elif e.button() == Qt.MidButton:
  20. self.input1.setText("MidButton press")
  21. def mouseReleaseEvent(self, e):
  22. if e.button() == Qt.RightButton:
  23. self.input2.setText("RightButton release")
  24. elif e.button() == Qt.LeftButton:
  25. self.input2.setText("LeftButton release")
  26. elif e.button() == Qt.BackButton:
  27. self.input2.setText("BackButton release")
  28. elif e.button() == Qt.ForwardButton:
  29. self.input2.setText("ForwardButton release")
  30. elif e.button() == Qt.MiddleButton:
  31. self.input2.setText("MiddleButton release")
  32. elif e.button() == Qt.MidButton:
  33. self.input2.setText("MidButton release")
  34. return
  35. def mouseDoubleClickEvent(self, e):
  36. if e.button() == Qt.RightButton:
  37. self.input3.setText("RightButton double")
  38. elif e.button() == Qt.LeftButton:
  39. self.input3.setText("LeftButton double")
  40. elif e.button() == Qt.BackButton:
  41. self.input3.setText("BackButton double")
  42. elif e.button() == Qt.ForwardButton:
  43. self.input3.setText("ForwardButton double")
  44. elif e.button() == Qt.MiddleButton:
  45. self.input3.setText("MiddleButton double")
  46. elif e.button() == Qt.MidButton:
  47. self.input3.setText("MidButton double")
  48. return
  49. def mouseMoveEvent(self, e):
  50. if e.button() == Qt.RightButton:
  51. self.input4.setText("RightButton move")
  52. elif e.button() == Qt.LeftButton:
  53. self.input4.setText("LeftButton move")
  54. elif e.button() == Qt.BackButton:
  55. self.input4.setText("BackButton move")
  56. elif e.button() == Qt.ForwardButton:
  57. self.input4.setText("ForwardButton move")
  58. elif e.button() == Qt.MiddleButton:
  59. self.input4.setText("MiddleButton move")
  60. elif e.button() == Qt.MidButton:
  61. self.input4.setText("MidButton move")
  62. return
  63. def mouseGrabber(self):
  64. return

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/人工智能uu/article/detail/863740
推荐阅读
相关标签
  

闽ICP备14008679号