1. 向 MainWindow 中添加主菜单栏
在 ui 中画好菜单并命名 action
代码示例
self.action_search_candidates_to_be_admitted.triggered.connect(self.fn_search_candidates_to_be_admitted)
2. 添加点击菜单
点击按钮或者右键出现菜单
代码示例
def fn_show_to_interview_menu(self, row):
self.curr_row_index = row
self.is_changed = 0
main_menu = QtWidgets.QMenu()
action_temporarily_lost = QtWidgets.QAction(u'暂时失联', self)
action_temporarily_unsuccessful_negotiation = QtWidgets.QAction(u'暂时协商未果', self)
action_always_lost_or_unsuccessful_negotiation = QtWidgets.QAction(u'始终失联或未果', self)
action_candidates_give_up = QtWidgets.QAction(u'候选人放弃', self)
main_menu.addAction(action_temporarily_lost)
main_menu.addAction(action_temporarily_unsuccessful_negotiation)
main_menu.addAction(action_always_lost_or_unsuccessful_negotiation)
main_menu.addAction(action_candidates_give_up)
main_menu.triggered[QAction].connect(self.fn_other_action_to_interview)
main_menu.exec_(QtGui.QCursor.pos())