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

标签 c++ qt qt5 qaction qtoolbar

我有一个工具栏或者有几个 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/

相关文章:

c++ - VSCode 中的 Code Runner 在输出中运行,而不是在终端中运行 CMD

c++ - 对 OOLUA::Proxy_class<T>::class_name 的 undefined reference

python - 在 PyQt 中清除一个 TableView

qt - 如何使用 QPluginLoader 在 Qt 中创建同一插件的多个实例?

c++ - QTableView 如何设置特殊行的背景色?

qt - 更改多列过滤的 QSortFilterProxyModel 行为

c++ - 为什么在 std::thread 启动后我的 while 循环不启动?

c++ - 从 QML 索引访问列表

c++ - QTreeView、QTableView,显示不同层级的项目

python - 如何为 Python 2.7 安装 Pyside?