user8632386
user8632386

Reputation:

How to change the color of a QAction that is in a toolbar?

I have a toolbar or there are several QActions. I would like to change the color of the QAction when it is selected so that the user can see the chosen action.

The problem is that QAction is not a QWidget so we can not use stylesheet. Is there a way to get around this problem? Or would it be better to declare QPushButton instead of QAction in my toolbar?

I would like, for example, that if I click on a QAction it is pushed against the others. I have 6 QAction declared in my toolbar.

Upvotes: 1

Views: 2890

Answers (1)

eyllanesc
eyllanesc

Reputation: 244282

You have to checkeable the QAction with:

your_action->setCheckable(true)

or using Qt Designer

enter image description here

and then set qss with QToolButton:

QToolButton:checked {background-color: red; }

enter image description here

Upvotes: 1

Related Questions