-1

I am trying to change the icon of a QMenu's right arrow. The following QSS rule works

QMenu::right-arrow {
    image: url(icons:icon_name.svg);
}

However, it changes the right arrows of all QMenus. I want to select only QMenus that have some property/name. I tried the following things:

/* shouldHide is a boolean property set to true */
QMenu[shouldHide="true"]::right-arrow {
    image: url(icons:icon_name.svg);
}
QMenu::right-arrow[shouldHide="true"] {
    image: url(icons:icon_name.svg);
}

I also tried wrapping the QMenu in a hidden QWidget and setting the stylesheet on the parent

container->setStyleSheet("QMenu::right-arrow: {image: url(icons:icon_name.svg); }");

I also attempted to set the style sheet on the menu itself in the following ways:

menu->setStyleSheet("QMenu::right-arrow: {image: url(icons:icon_name.svg); }");
menu->setStyleSheet("*::right-arrow: {image: url(icons:icon_name.svg); }");

... and none of them work.

Borislav-K
  • 11
  • 2
  • `QMenu#menu_object_name::right-arrow` Did you try this? – Parisa.H.R Aug 23 '21 at 10:05
  • Yes, I did. It does not work. – Borislav-K Aug 23 '21 at 10:14
  • in `qss` there is priority between styles, which means that you shouldn't add style for general QMenu First and then add `QMenu#menu_object_name::right-arrow` the first style and style that are upper has first priority so put your .qss file to question . – Parisa.H.R Aug 23 '21 at 10:18

1 Answers1

-1

This style will be applied for all QMenu Objects:

QMenu::right-arrow 
{
        image: url(icons:icon_name.svg);
}

If you want only to apply to a specific object, you could use the object name of the object:

Only Object Name:

#my_object_name::right-arrow 
{
        image: url(icons:icon_name.svg);
}

Object Name Of A Specefic Type

QMenu#my_object_name::right-arrow 
{
        image: url(icons:icon_name.svg);
}
Ghasem Ramezani
  • 2,683
  • 1
  • 13
  • 32