PDA

View Full Version : Style QPushButton differently whether has Icon or not?



pablogil
7th March 2016, 13:36
Hi,

Is it possible to style QPushButtons separately from a qss stylesheet whether if it has an icon applied or not? Something like:

QPushButton[hasIcon="true"] {
background-color: green;
}
QPushButton[hasIcon="false"] {
background-color: red;
}

Thank you

ChrisW67
12th March 2016, 05:36
If you set a dynamic property "hasIcon" when you set/unset the icon on a button then this should work. While the button already has an icon property I do not think it is usable in this context.

pablogil
12th March 2016, 19:29
Thank you ChrisW67, I'm not C++ coder, just a CSS/QT designer... do you know how can I create this dynamic property if I have detected this code?:

self.pointButton = self._pushbutton("addButton", bl, icon="Draft_AddPoint", width=100)
Source code taken from here (https://github.com/FreeCAD/FreeCAD/blob/master/src/Mod/Draft/DraftGui.py#L402).

Thank you

ChrisW67
13th March 2016, 20:48
At a guess...


if icon:
button.setProperty('hasIcon', 'yes')

In the_pushbutton() function at line 297 would do it.