I want to set icon of QAction using qss file. I cannot set stylesheet to QAction so I want to convert it to a QWidget so that I can add icon to individual actions of QMenu using stylesheet. I know how to do that in code by I want to add Icon of QActions using qss.
QMenu* menu = new QMenu();
QAction* newFile = new QAction;
newFile->setText("New File");
menu->addAction(newFile);
I want to set icon to QAction in qss.
QMenu *menu;
menu =new QMenu();
QToolButton *button=new QToolButton(menu);
button->setFixedSize(50,50);
QWidgetAction *action=new QWidgetAction(this);
action->setDefaultWidget(button);
menu->addAction(action);
Use QToolButton instead of QAction and you can set the icon using setStyleSheet() or setIcon()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.