17
17
18
18
try :
19
19
from PyQt5 .QtCore import Qt
20
- from PyQt5 .QtWidgets import QWidget , QPushButton , QApplication
20
+ from PyQt5 .QtGui import QCursor
21
+ from PyQt5 .QtWidgets import QApplication , QPushButton , QWidget
21
22
from PyQt5 .QtWinExtras import QtWin
22
23
except ImportError :
23
24
from PySide2 .QtCore import Qt
24
- from PySide2 .QtWidgets import QWidget , QPushButton , QApplication
25
+ from PySide2 .QtGui import QCursor
26
+ from PySide2 .QtWidgets import QApplication , QPushButton , QWidget
25
27
from PySide2 .QtWinExtras import QtWin
26
28
27
29
@@ -43,16 +45,15 @@ def __init__(self, *args, **kwargs):
43
45
# 主屏幕的可用大小(去掉任务栏)
44
46
self ._rect = QApplication .instance ().desktop ().availableGeometry (self )
45
47
self .resize (800 , 600 )
46
- self .setWindowFlags (Qt .Window
47
- | Qt .FramelessWindowHint
48
- | Qt .WindowSystemMenuHint
49
- | Qt .WindowMinimizeButtonHint
50
- | Qt .WindowMaximizeButtonHint
51
- | Qt .WindowCloseButtonHint )
48
+ self .setWindowFlags (Qt .Window | Qt .FramelessWindowHint |
49
+ Qt .WindowSystemMenuHint |
50
+ Qt .WindowMinimizeButtonHint |
51
+ Qt .WindowMaximizeButtonHint |
52
+ Qt .WindowCloseButtonHint )
52
53
# 增加薄边框
53
54
style = win32gui .GetWindowLong (int (self .winId ()), win32con .GWL_STYLE )
54
- win32gui .SetWindowLong (
55
- int ( self . winId ()), win32con . GWL_STYLE , style | win32con .WS_THICKFRAME )
55
+ win32gui .SetWindowLong (int ( self . winId ()), win32con . GWL_STYLE ,
56
+ style | win32con .WS_THICKFRAME )
56
57
57
58
if QtWin .isCompositionEnabled ():
58
59
# 加上 Aero 边框阴影
@@ -65,8 +66,9 @@ def nativeEvent(self, eventType, message):
65
66
if eventType == "windows_generic_MSG" :
66
67
msg = ctypes .wintypes .MSG .from_address (message .__int__ ())
67
68
# 获取鼠标移动经过时的坐标
68
- x = win32api .LOWORD (msg .lParam ) - self .frameGeometry ().x ()
69
- y = win32api .HIWORD (msg .lParam ) - self .frameGeometry ().y ()
69
+ pos = QCursor .pos ()
70
+ x = pos .x () - self .frameGeometry ().x ()
71
+ y = pos .y () - self .frameGeometry ().y ()
70
72
# 判断鼠标位置是否有其它控件
71
73
if self .childAt (x , y ) != None :
72
74
return retval , result
@@ -75,8 +77,8 @@ def nativeEvent(self, eventType, message):
75
77
return True , 0
76
78
if msg .message == win32con .WM_GETMINMAXINFO :
77
79
# 当窗口位置改变或者大小改变时会触发该消息
78
- info = ctypes .cast (
79
- msg . lParam , ctypes .POINTER (MINMAXINFO )).contents
80
+ info = ctypes .cast (msg . lParam ,
81
+ ctypes .POINTER (MINMAXINFO )).contents
80
82
# 修改最大化的窗口大小为主屏幕的可用大小
81
83
info .ptMaxSize .x = self ._rect .width ()
82
84
info .ptMaxSize .y = self ._rect .height ()
0 commit comments