Is it possible to change the colour of the part icon or associated text in the Labels and Attributes window?
I would like to have some indicator that certain parts are different from others and to be able to change this under program control.
Change Colour of a Part Icon or Text.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
-
- Veteran
- Posts: 2756
- Joined: Mon Feb 27, 2012 5:31 pm
-
- Veteran
- Posts: 2756
- Joined: Mon Feb 27, 2012 5:31 pm
Re: Change Colour of a Part Icon or Text.
Okay I see that if I access the View Object for a Part I can access the icon i.e.
I get
So how do I set vpart.Icon to some SVG icon?
Code: Select all
part = parent.newObject("App::Part",volref)
vpart = part.ViewObject
print(dir(vpart))
print(vpart.Icon)
Code: Select all
['Annotation', 'Content', 'DisplayMode', 'Document', 'IV', 'Icon', 'MemSize', 'Module', 'Object', 'PropertiesList', 'RootNode', 'TypeId', 'Visibility', '__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'addDisplayMode', 'addExtension', 'addProperty', 'claimChildren', 'dumpContent', 'dumpPropertyContent', 'getAllDerivedFrom', 'getDocumentationOfProperty', 'getEditorMode', 'getGroupOfProperty', 'getPropertyByName', 'getTypeIdOfProperty', 'getTypeOfProperty', 'hasExtension', 'hide', 'isDerivedFrom', 'isVisible', 'listDisplayModes', 'removeProperty', 'restoreContent', 'restorePropertyContent', 'setEditorMode', 'setTransformation', 'show', 'supportedProperties', 'toString', 'update']
<PySide2.QtGui.QIcon(availableSizes[normal,Off]=(QSize(64, 64)),cacheKey=0xfff00000000) at 0x7f276f9ccec8>
Re: Change Colour of a Part Icon or Text.
The only example I can think of where an icon in the Treeview changes colour is the Draft>Layers function. the user can specify the Line Colour and Shape Colour of the layer and it is reflected in the icon as per:
Please don't ask me how it works but the file in question to review would be src\Mod\Draft\DraftLayer.py
Please don't ask me how it works but the file in question to review would be src\Mod\Draft\DraftLayer.py
-
- Veteran
- Posts: 2756
- Joined: Mon Feb 27, 2012 5:31 pm
Re: Change Colour of a Part Icon or Text.
Okay tried to set the icon with
But got message Attribute 'Icon' of object 'ViewProvider' is read-only
Code: Select all
from PySide import QtGui,QtCore
f2=QtCore.QFileInfo("icons:PartDesign_Chamfer.svg") # use "icons:" as prefix
vpart.Icon = f2