本文整理汇总了Python中PyQt5.QtWidgets.QAction.state方法的典型用法代码示例。如果您正苦于以下问题:Python QAction.state方法的具体用法?Python QAction.state怎么用?Python QAction.state使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QAction
的用法示例。
在下文中一共展示了QAction.state方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setState
# 需要导入模块: from PyQt5.QtWidgets import QAction [as 别名]
# 或者: from PyQt5.QtWidgets.QAction import state [as 别名]
def setState(self, state, note=None):
if state == self.state and note == self.note:
return
self.state = state
self.note = note
palette = self.palette()
palette.setColor(QPalette.Button, QColor(state.color))
self.setPalette(palette)
if note and not state.internal:
menu = self.menu()
actions = menu.actions()[5:]
try:
action = next(action for action in actions if action.state is state and action.note == note)
except StopIteration:
action = QAction(QIcon(state.icon), note, menu)
if len(actions) == 0:
menu.addAction(action)
else:
if len(actions) >= self.history_size:
menu.removeAction(actions[-1])
menu.insertAction(actions[0], action)
action.state = state
action.note = note
else:
if action is not actions[0]:
menu.removeAction(action)
menu.insertAction(actions[0], action)
self.stateChanged.emit()