MCPcopy Create free account
hub / github.com/PyQt5/PyQtClient / mouseMoveEvent

Method mouseMoveEvent

Widgets/FramelessWindow.py:72–121  ·  view source on GitHub ↗
(self, event)

Source from the content-addressed store, hash-verified

70 self.showMaximized()
71
72 def mouseMoveEvent(self, event):
73 # 鼠标移动事件
74 super(FramelessWindow, self).mouseMoveEvent(event)
75
76 pos = event.pos()
77 xPos, yPos = pos.x(), pos.y()
78 wm, hm = self.width() - self.MARGIN, self.height() - self.MARGIN
79 if self.isMaximized() or self.isFullScreen():
80 # 最大化或者全屏则忽略
81 self.Direction = None
82 self.setCursor(Qt.ArrowCursor)
83 return
84 if self._canmove:
85 self.move(self.mapToGlobal(event.pos() - self._pos))
86 return
87 if event.buttons() == Qt.LeftButton and self._pressed:
88 self._resizeWidget(pos)
89 return
90 if xPos <= self.MARGIN and yPos <= self.MARGIN:
91 # 左上角
92 self.Direction = LeftTop
93 self.setCursor(Qt.SizeFDiagCursor)
94 elif wm <= xPos <= self.width() and hm <= yPos <= self.height():
95 # 右下角
96 self.Direction = RightBottom
97 self.setCursor(Qt.SizeFDiagCursor)
98 elif wm <= xPos and yPos <= self.MARGIN:
99 # 右上角
100 self.Direction = RightTop
101 self.setCursor(Qt.SizeBDiagCursor)
102 elif xPos <= self.MARGIN and hm <= yPos:
103 # 左下角
104 self.Direction = LeftBottom
105 self.setCursor(Qt.SizeBDiagCursor)
106 elif 0 <= xPos <= self.MARGIN and self.MARGIN <= yPos <= hm:
107 # 左边
108 self.Direction = Left
109 self.setCursor(Qt.SizeHorCursor)
110 elif wm <= xPos <= self.width() and self.MARGIN <= yPos <= hm:
111 # 右边
112 self.Direction = Right
113 self.setCursor(Qt.SizeHorCursor)
114 elif self.MARGIN <= xPos <= wm and 0 <= yPos <= self.MARGIN:
115 # 上面
116 self.Direction = Top
117 self.setCursor(Qt.SizeVerCursor)
118 elif self.MARGIN <= xPos <= wm and hm <= yPos <= self.height():
119 # 下面
120 self.Direction = Bottom
121 self.setCursor(Qt.SizeVerCursor)
122
123 def leaveEvent(self, event):
124 # 鼠标离开事件

Callers

nothing calls this directly

Calls 3

moveMethod · 0.95
_resizeWidgetMethod · 0.95
xMethod · 0.45

Tested by

no test coverage detected