Change Colour of a Part Icon or Text.

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
keithsloan52
Veteran
Posts: 2756
Joined: Mon Feb 27, 2012 5:31 pm

Change Colour of a Part Icon or Text.

Post by keithsloan52 »

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.
keithsloan52
Veteran
Posts: 2756
Joined: Mon Feb 27, 2012 5:31 pm

Re: Change Colour of a Part Icon or Text.

Post by keithsloan52 »

Okay I see that if I access the View Object for a Part I can access the icon i.e.

Code: Select all

part = parent.newObject("App::Part",volref)
vpart = part.ViewObject
print(dir(vpart))
print(vpart.Icon)
I get

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>
So how do I set vpart.Icon to some SVG icon?
Syres
Veteran
Posts: 2893
Joined: Thu Aug 09, 2018 11:14 am

Re: Change Colour of a Part Icon or Text.

Post by Syres »

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:
ColouredTreeViewIcons.jpg
ColouredTreeViewIcons.jpg (6.88 KiB) Viewed 537 times
Please don't ask me how it works but the file in question to review would be src\Mod\Draft\DraftLayer.py
keithsloan52
Veteran
Posts: 2756
Joined: Mon Feb 27, 2012 5:31 pm

Re: Change Colour of a Part Icon or Text.

Post by keithsloan52 »

Okay tried to set the icon with

Code: Select all

from PySide import QtGui,QtCore

f2=QtCore.QFileInfo("icons:PartDesign_Chamfer.svg") # use "icons:" as prefix
vpart.Icon = f2
But got message Attribute 'Icon' of object 'ViewProvider' is read-only :(
Post Reply