MCPcopy Index your code
hub / github.com/PyQt5/PyQt / Window

Class Window

Demo/NativeEvent.py:40–119  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38
39
40class Window(QWidget):
41 BorderWidth = 5
42
43 def __init__(self, *args, **kwargs):
44 super(Window, self).__init__(*args, **kwargs)
45 # 主屏幕的可用大小(去掉任务栏)
46 self._rect = QApplication.instance().desktop().availableGeometry(self)
47 self.resize(800, 600)
48 self.setWindowFlags(Qt.Window | Qt.FramelessWindowHint |
49 Qt.WindowSystemMenuHint |
50 Qt.WindowMinimizeButtonHint |
51 Qt.WindowMaximizeButtonHint |
52 Qt.WindowCloseButtonHint)
53 # 增加薄边框
54 style = win32gui.GetWindowLong(int(self.winId()), win32con.GWL_STYLE)
55 win32gui.SetWindowLong(int(self.winId()), win32con.GWL_STYLE,
56 style | win32con.WS_THICKFRAME)
57
58 if QtWin.isCompositionEnabled():
59 # 加上 Aero 边框阴影
60 QtWin.extendFrameIntoClientArea(self, -1, -1, -1, -1)
61 else:
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):

Callers 1

NativeEvent.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected