我有一个工具栏或者有几个 QAction。我想在选择 QAction 时更改它的颜色,以便用户可以看到所选的操作。
问题是 QAction 不是 QWidget,所以我们不能使用样式表。 有没有办法解决这个问题? 或者在我的工具栏中声明 QPushButton 而不是 QAction 会更好吗?
例如,如果我点击 QAction,它会被推到其他 QAction 上。我的工具栏中声明了 6 个 QAction。
最佳答案
你必须checkeable
QAction
:
your_action->setCheckable(true)
或使用 Qt Designer
然后用QToolButton设置qss:
QToolButton:checked {background-color: red; }
关于c++ - 如何更改工具栏中 QAction 的颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51168943/