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

Method mouseMoveEvent

Demo/Lib/FramelessWindow.py:238–282  ·  view source on GitHub ↗

鼠标移动事件

(self, event)

Source from the content-addressed store, hash-verified

236 self.Direction = None
237
238 def mouseMoveEvent(self, event):
239 """鼠标移动事件"""
240 super(FramelessWindow, self).mouseMoveEvent(event)
241 pos = event.pos()
242 xPos, yPos = pos.x(), pos.y()
243 wm, hm = self.width() - self.Margins, self.height() - self.Margins
244 if self.isMaximized() or self.isFullScreen():
245 self.Direction = None
246 self.setCursor(Qt.ArrowCursor)
247 return
248 if event.buttons() == Qt.LeftButton and self._pressed:
249 self._resizeWidget(pos)
250 return
251 if xPos <= self.Margins and yPos <= self.Margins:
252 # 左上角
253 self.Direction = LeftTop
254 self.setCursor(Qt.SizeFDiagCursor)
255 elif wm <= xPos <= self.width() and hm <= yPos <= self.height():
256 # 右下角
257 self.Direction = RightBottom
258 self.setCursor(Qt.SizeFDiagCursor)
259 elif wm <= xPos and yPos <= self.Margins:
260 # 右上角
261 self.Direction = RightTop
262 self.setCursor(Qt.SizeBDiagCursor)
263 elif xPos <= self.Margins and hm <= yPos:
264 # 左下角
265 self.Direction = LeftBottom
266 self.setCursor(Qt.SizeBDiagCursor)
267 elif 0 <= xPos <= self.Margins and self.Margins <= yPos <= hm:
268 # 左边
269 self.Direction = Left
270 self.setCursor(Qt.SizeHorCursor)
271 elif wm <= xPos <= self.width() and self.Margins <= yPos <= hm:
272 # 右边
273 self.Direction = Right
274 self.setCursor(Qt.SizeHorCursor)
275 elif self.Margins <= xPos <= wm and 0 <= yPos <= self.Margins:
276 # 上面
277 self.Direction = Top
278 self.setCursor(Qt.SizeVerCursor)
279 elif self.Margins <= xPos <= wm and hm <= yPos <= self.height():
280 # 下面
281 self.Direction = Bottom
282 self.setCursor(Qt.SizeVerCursor)
283
284 def _resizeWidget(self, pos):
285 """调整窗口大小"""

Callers

nothing calls this directly

Calls 6

_resizeWidgetMethod · 0.95
yMethod · 0.80
mouseMoveEventMethod · 0.45
xMethod · 0.45
widthMethod · 0.45
heightMethod · 0.45

Tested by

no test coverage detected