Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个工具栏或有几个 QAction。我想在选择 QAction 时更改它的颜色,以便用户可以看到选择的操作。
问题是 QAction 不是 QWidget 所以我们不能使用样式表。有没有办法解决这个问题?或者在我的工具栏中声明 QPushButton 而不是 QAction 会更好吗?
例如,我希望如果我点击一个 QAction,它会被推送到其他人身上。我在我的工具栏中声明了 6 个 QAction。
你必须checkeable与QAction:
checkeable
QAction
your_action->setCheckable(true)
或使用 Qt 设计器
然后用 QToolButton 设置 qss:
QToolButton:checked {background-color: red; }