gpt4 book ai didi

qt - 如何在上下文菜单中添加选中/取消选中 QAction?

转载 作者:行者123 更新时间:2023-12-04 13:17:04 26 4
gpt4 key购买 nike

我在 Qt 中创建了一个上下文菜单,我需要菜单中的项目以选中/未选中的方式工作,以便每次点击相应项目时切换。如何将此功能添加到 QAction 中,如下所示? enter image description here

最佳答案

这是手册中的相关部分。

checkable : bool

This property holds whether the action is a checkable action.

A checkable action is one which has an on/off state. For example, in a word processor, a Bold toolbar button may be either on or off. An action which is not a toggle action is a command action; a command action is simply executed, e.g. file save. By default, this property is false.

In some situations, the state of one toggle action should depend on the state of others. For example, "Left Align", "Center" and "Right Align" toggle actions are mutually exclusive. To achieve exclusive toggling, add the relevant toggle actions to a QActionGroup with the QActionGroup::exclusive property set to true.

Access functions:

bool isCheckable() const

void setCheckable(bool)

Notifier signal:

void changed()

关于qt - 如何在上下文菜单中添加选中/取消选中 QAction?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13506201/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com