MCPcopy
hub / github.com/PyQt5/PyQt / init_menu

Method init_menu

QMenu/QQMenu.py:96–122  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

94 self.context_menu.exec_(event.globalPos())
95
96 def init_menu(self):
97 # 背景透明
98 self.context_menu.setAttribute(Qt.WA_TranslucentBackground)
99 # 无边框、去掉自带阴影
100 self.context_menu.setWindowFlags(
101 self.context_menu.windowFlags() | Qt.FramelessWindowHint | Qt.NoDropShadowWindowHint)
102
103 # 模拟菜单项
104 for i in range(10):
105 if i % 2 == 0:
106 action = self.context_menu.addAction('菜单 %d' % i, about_qt)
107 action.setEnabled(i % 4)
108 elif i % 3 == 0:
109 self.context_menu.addAction(get_icon(), '菜单 %d' % i, about_qt)
110 if i % 4 == 0:
111 self.context_menu.addSeparator()
112 if i % 5 == 0:
113 # 二级菜单
114 # 二级菜单
115 menu = QMenu('二级菜单 %d' % i, self.context_menu)
116 # 背景透明
117 menu.setAttribute(Qt.WA_TranslucentBackground)
118 # 无边框、去掉自带阴影
119 menu.setWindowFlags(menu.windowFlags() | Qt.FramelessWindowHint | Qt.NoDropShadowWindowHint)
120 for j in range(3):
121 menu.addAction(get_icon(), '子菜单 %d' % j)
122 self.context_menu.addMenu(menu)
123
124
125if __name__ == '__main__':

Callers 1

__init__Method · 0.95

Calls 1

get_iconFunction · 0.85

Tested by

no test coverage detected