<div dir="ltr"><div dir="ltr"><div>Hi all</div><div>Iam trying to add legend to the print layout of a polyline that have been created using QgsLayoutItemPolyline.</div><div>I managed to draw the polyline on the map composer and play with its properties, but could not add the corresponding line to the legend.</div><div>Any ideas/suggestions?</div><div>The code that corresponds to the legend is:</div><div><br></div><div>polygon2 = QPolygonF()</div><div>polygon2.append(QPointF(50.0, 150.0))</div><div>polygon2.append(QPointF(150.0, 80.0))</div><div>polygon2.append(QPointF(250.0, 100.0))</div><div>polygon2.append(QPointF(10.0, 200.0))</div><div>layoutItemPolyline = QgsLayoutItemPolyline(polygon2, layout)</div><div>layout.addLayoutItem(layoutItemPolyline)</div><div><br></div><div>props = {}</div><div>props["color"] = "green"</div><div>props["style"] = "solid"</div><div><br></div><div>symbol = QgsLineSymbol.createSimple(props)<br></div><div>layoutItemPolyline.setSymbol(symbol)</div><div>legend = QgsLayoutItemLegend(layout)<br></div><div>legend.setAutoUpdateModel(False)<br></div><div>root = legend.model().rootGroup()</div><div>legend = QgsLayoutItemLegend(layout)<br></div><div>legend.setTitle("Legend")</div><div>legend.setAutoUpdateModel(False)<br></div><div>legend.setLinkedMap(map)<br></div><div>legend.setLegendFilterByMapEnabled(True)<br></div><div>layout.addLayoutItem(legend)<br></div><div>legend.attemptMove(QgsLayoutPoint(235, 36, QgsUnitTypes.LayoutMillimeters))</div><div><br></div><div><br></div><div>Thanks in advance</div><div>Kind regards,</div><div>Asim</div></div></div>