<div dir="ltr">I have several plugin functions that are using QgsProcessingLayerPostProcessorInterface to style the layer after it is created in a processing algorithm. I have largely ignored the fact that after I style it, the legend displayed in the layers panel is its old style and not the new one. I have a solution, but don't know if I am violating some thread safe rule. I know I cannot use iface in the algorithm, but is it safe to use in QgsProcessingLayerPostProcessorInterface?<div><br></div><div>In the top of my algorithm I import the following:</div><div><br></div><div><font face="monospace">from qgis.utils import iface</font><br></div><div><br></div><div>In the <font face="monospace">processAlgorithm </font>function I have the following.</div><div><br></div><div><font face="monospace">if context.willLoadLayerOnCompletion(dest_id):</font></div><div><font face="monospace">    context.layerToLoadOnCompletionDetails(dest_id).setPostProcessor(StylePostProcessor.create(settings.lineColor, settings.fontColor))<br>return {self.PrmOutput: dest_id}</font><br></div><div><br></div><div>My QgsProcessingLayerPostProcessorInterface looks like this. Notice the line <font face="monospace">iface.layerTreeView().refreshLayerSymbology(<a href="http://layer.id">layer.id</a>()) </font>which effectively does what I need it to do. It works, but is safe or is there a better way to do this? The output layer is a polygon in which I only want the outline displayed. I am passing some color parameters from processAlgorithm.</div><div><br></div><div><font face="monospace">class StylePostProcessor(QgsProcessingLayerPostProcessorInterface):<br>    instance = None<br>    line_color = None<br>    font_color = None<br><br>    def __init__(self, line_color, font_color):<br>        self.line_color = line_color<br>        self.font_color = font_color<br>        super().__init__()<br><br>    def postProcessLayer(self, layer, context, feedback):<br><br>        if not isinstance(layer, QgsVectorLayer):<br>            return<br>        sym = layer.renderer().symbol().symbolLayer(0)<br>        sym.setBrushStyle(Qt.NoBrush)<br>        sym.setStrokeColor(self.line_color)<br>       <b> iface.layerTreeView().refreshLayerSymbology(<a href="http://layer.id">layer.id</a>())</b><br><br>    # Hack to work around sip bug!<br>    @staticmethod<br>    def create(line_color, font_color) -> 'StylePostProcessor':<br>        """<br>        Returns a new instance of the post processor, keeping a reference to the sip<br>        wrapper so that sip doesn't get confused with the Python subclass and call<br>        the base wrapper implementation instead... ahhh sip, you wonderful piece of sip<br>        """<br>        StylePostProcessor.instance = StylePostProcessor(line_color, font_color)<br>        return StylePostProcessor.instance</font><br></div></div>