本文整理汇总了Python中AnyQt.QtWidgets.QAction.trigger方法的典型用法代码示例。如果您正苦于以下问题:Python QAction.trigger方法的具体用法?Python QAction.trigger怎么用?Python QAction.trigger使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AnyQt.QtWidgets.QAction
的用法示例。
在下文中一共展示了QAction.trigger方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_tool_grid
# 需要导入模块: from AnyQt.QtWidgets import QAction [as 别名]
# 或者: from AnyQt.QtWidgets.QAction import trigger [as 别名]
def test_tool_grid(self):
w = ToolGrid()
w.show()
self.app.processEvents()
def buttonsOrderedVisual():
# Process layout events so the buttons have right positions
self.app.processEvents()
buttons = w.findChildren(QToolButton)
return list(sorted(buttons, key=lambda b: (b.y(), b.x())))
def buttonsOrderedLogical():
return list(map(w.buttonForAction, w.actions()))
def assertOrdered():
self.assertSequenceEqual(buttonsOrderedLogical(),
buttonsOrderedVisual())
action_a = QAction("A", w)
action_b = QAction("B", w)
action_c = QAction("C", w)
action_d = QAction("D", w)
w.addAction(action_b)
w.insertAction(0, action_a)
self.assertSequenceEqual(w.actions(),
[action_a, action_b])
assertOrdered()
w.addAction(action_d)
w.insertAction(action_d, action_c)
self.assertSequenceEqual(w.actions(),
[action_a, action_b, action_c, action_d])
assertOrdered()
w.removeAction(action_c)
self.assertSequenceEqual(w.actions(),
[action_a, action_b, action_d])
assertOrdered()
w.removeAction(action_a)
self.assertSequenceEqual(w.actions(),
[action_b, action_d])
assertOrdered()
w.insertAction(0, action_a)
self.assertSequenceEqual(w.actions(),
[action_a, action_b, action_d])
assertOrdered()
w.setColumnCount(2)
self.assertSequenceEqual(w.actions(),
[action_a, action_b, action_d])
assertOrdered()
w.insertAction(2, action_c)
self.assertSequenceEqual(w.actions(),
[action_a, action_b, action_c, action_d])
assertOrdered()
w.clear()
# test no 'before' action edge case
w.insertAction(0, action_a)
self.assertIs(action_a, w.actions()[0])
w.insertAction(1, action_b)
self.assertSequenceEqual(w.actions(),
[action_a, action_b])
w.clear()
w.setActions([action_a, action_b, action_c, action_d])
self.assertSequenceEqual(w.actions(),
[action_a, action_b, action_c, action_d])
assertOrdered()
triggered_actions = []
def p(action):
print(action.text())
w.actionTriggered.connect(p)
w.actionTriggered.connect(triggered_actions.append)
action_a.trigger()
w.show()
self.app.exec_()