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

Method nativeEvent

Demo/NativeEvent.py:64–119  ·  view source on GitHub ↗
(self, eventType, message)

Source from the content-addressed store, hash-verified

62 QtWin.resetExtendedFrame(self)
63
64 def nativeEvent(self, eventType, message):
65 retval, result = super(Window, self).nativeEvent(eventType, message)
66 if eventType == "windows_generic_MSG":
67 msg = ctypes.wintypes.MSG.from_address(message.__int__())
68 # 获取鼠标移动经过时的坐标
69 pos = QCursor.pos()
70 x = pos.x() - self.frameGeometry().x()
71 y = pos.y() - self.frameGeometry().y()
72 # 判断鼠标位置是否有其它控件
73 if self.childAt(x, y) != None:
74 return retval, result
75 if msg.message == win32con.WM_NCCALCSIZE:
76 # 拦截不显示顶部的系统自带的边框
77 return True, 0
78 if msg.message == win32con.WM_GETMINMAXINFO:
79 # 当窗口位置改变或者大小改变时会触发该消息
80 info = ctypes.cast(msg.lParam,
81 ctypes.POINTER(MINMAXINFO)).contents
82 # 修改最大化的窗口大小为主屏幕的可用大小
83 info.ptMaxSize.x = self._rect.width()
84 info.ptMaxSize.y = self._rect.height()
85 # 修改放置点的x,y坐标为0,0
86 info.ptMaxPosition.x, info.ptMaxPosition.y = 0, 0
87 if msg.message == win32con.WM_NCHITTEST:
88 w, h = self.width(), self.height()
89 lx = x < self.BorderWidth
90 rx = x > w - self.BorderWidth
91 ty = y < self.BorderWidth
92 by = y > h - self.BorderWidth
93 # 左上角
94 if (lx and ty):
95 return True, win32con.HTTOPLEFT
96 # 右下角
97 if (rx and by):
98 return True, win32con.HTBOTTOMRIGHT
99 # 右上角
100 if (rx and ty):
101 return True, win32con.HTTOPRIGHT
102 # 左下角
103 if (lx and by):
104 return True, win32con.HTBOTTOMLEFT
105 # 上
106 if ty:
107 return True, win32con.HTTOP
108 # 下
109 if by:
110 return True, win32con.HTBOTTOM
111 # 左
112 if lx:
113 return True, win32con.HTLEFT
114 # 右
115 if rx:
116 return True, win32con.HTRIGHT
117 # 标题
118 return True, win32con.HTCAPTION
119 return retval, result
120
121

Callers

nothing calls this directly

Calls 4

yMethod · 0.80
xMethod · 0.45
widthMethod · 0.45
heightMethod · 0.45

Tested by

no test coverage detected