I am able to intercept the property change in view provider class updateData(self, fp, prop).
In this function I am able to parse the tree widget to find my feature python object and use qt setIcon() to change the icon dynamically, but this is failing in my ubuntu virtual machine, but works in windows. I'd rather do it in FreeCAD as opposed to using qt setIcon() on the tree widget item.
Here is a piece of the code as it stands for the moment with some debugging messages.
Code: Select all
def updateData(self, fp, prop):
'''If a property of the handled feature has changed we have the chance to handle this here'''
# fp is the handled feature, prop is the name of the property that has changed
#FreeCAD.Console.PrintMessage(prop+" is now "+str(getattr(fp,prop))+chr(10))
# heartXPM = ['7 6 2 1','N c None','. c #e2385a','N..N..N',\
#'.......','.......','N.....N','NN...NN','NNN.NNN']
if prop == "HasIntersection":
from PySide import QtCore,QtGui
win = FreeCADGui.getMainWindow()
item = None
trees = Gui.getMainWindow().findChildren(QtGui.QTreeWidget)
for tree in trees:
items = tree.findItems(fp.Label,QtCore.Qt.MatchWrap)
if len(items) == 1:
item = items[0]
FreeCAD.Console.PrintMessage("item found\n")
break
if item:
xpm = self.getIcon().replace("\"","").replace(',','').splitlines()[4:-1]
pixmap = QtGui.QPixmap(xpm)
if pixmap.isNull():
FreeCAD.Console.PrintMessage("pixmap is null\n")
icon = QtGui.QIcon(pixmap)
if icon.isNull():
FreeCAD.Console.PrintMessage("icon is null\n")
else:
FreeCAD.Console.PrintMessage("icon is not null\n")
#item.setIcon(0,icon)
item.setToolTip(0,"Has Intersection" if fp.HasIntersection else "No intersection or infinite intersections")
item.setForeground(1,QtGui.QColor(0,0,0) if fp.HasIntersection else QtGui.QColor(255,0,0))
else:
FreeCAD.Console.PrintMessage("unable to find object in tree\n")
The commented out heartXPM is an example of an xpm string that works with setIcon().
I was hoping there might be a touch() function or something similar to get the icon fetched again and redrawn.