gpt4 book ai didi

c++ - 如何更改工具栏中 QAction 的颜色?

转载 作者:行者123 更新时间:2023-11-30 04:59:32 25 4
gpt4 key购买 nike

我有一个工具栏或者有几个 QAction。我想在选择 QAction 时更改它的颜色,以便用户可以看到所选的操作。

问题是 QAction 不是 QWidget,所以我们不能使用样式表。有没有办法解决这个问题?或者在我的工具栏中声明 QPushButton 而不是 QAction 会更好吗?

例如,如果我点击 QAction,它会被推到其他 QAction 上。我的工具栏中声明了 6 个 QAction。

最佳答案

你必须checkeableQAction:

your_action->setCheckable(true)

或使用 Qt Designer

enter image description here

然后用QToolButton设置qss:

QToolButton:checked {background-color: red; }

enter image description here

关于c++ - 如何更改工具栏中 QAction 的颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51168943/

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