Set an Icon in QMenu with Stylesheet?

1.4k Views Asked by At

how can i set an Icon for a QAction in QMenu through Stylesheet?

for example:

QMenu* menu = new QMenu();

QAction* action1= new QAction();
QACtion* action2= new QAction();

menu->addAction(action1);
menu->addAction(action2);

now i want to set different icon for action1 and action2 with QT Stylesheet.

Is it possible with Stylesheet?

1

There are 1 best solutions below

0
On BEST ANSWER

Stylesheets only apply to widgets.

Qt Style Sheets are a powerful mechanism that allows you to customize the appearance of widgets, in addition to what is already possible by subclassing QStyle.

QAction is not a widget, thus you can't add an icon to a QAction via the style sheets. However, you could probably have a shot with QActionWidget and for example a QLabel, even if it can be tricky.