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

Class FramelessObject

Demo/NewFramelessWindow.py:26–132  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24
25
26class FramelessObject(QObject):
27 Margins = 3 # 边缘边距
28 TitleHeight = 36 # 标题栏高度
29 Widgets = set() # 无边框窗口集合
30
31 @classmethod
32 def set_margins(cls, margins):
33 cls.Margins = margins
34
35 @classmethod
36 def set_title_height(cls, height):
37 cls.TitleHeight = height
38
39 @classmethod
40 def add_widget(cls, widget):
41 cls.Widgets.add(widget)
42
43 @classmethod
44 def del_widget(cls, widget):
45 if widget in cls.Widgets:
46 cls.Widgets.remove(widget)
47
48 def _get_edges(self, pos, width, height):
49 """根据坐标获取方向
50 :param pos: QPoint
51 :param width: int
52 :param height: int
53 :return: Qt.Edges
54 """
55 edge = 0
56 x, y = pos.x(), pos.y()
57
58 if y <= self.Margins:
59 edge |= Qt.TopEdge
60 if x <= self.Margins:
61 edge |= Qt.LeftEdge
62 if x >= width - self.Margins:
63 edge |= Qt.RightEdge
64 if y >= height - self.Margins:
65 edge |= Qt.BottomEdge
66
67 return edge
68
69 def _get_cursor(self, edges):
70 """调整鼠标样式
71 :param edges: int or None
72 :return: Qt.CursorShape
73 """
74 if edges == Qt.LeftEdge | Qt.TopEdge or edges == Qt.RightEdge | Qt.BottomEdge:
75 return Qt.SizeFDiagCursor
76 elif edges == Qt.RightEdge | Qt.TopEdge or edges == Qt.LeftEdge | Qt.BottomEdge:
77 return Qt.SizeBDiagCursor
78 elif edges == Qt.LeftEdge or edges == Qt.RightEdge:
79 return Qt.SizeHorCursor
80 elif edges == Qt.TopEdge or edges == Qt.BottomEdge:
81 return Qt.SizeVerCursor
82
83 return Qt.ArrowCursor

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected