es.davy.ai

Preguntas y respuestas de programación confiables

¿Tienes una pregunta?

Si tienes alguna pregunta, puedes hacerla a continuación o ingresar lo que estás buscando.

PYQgis – agregar borde a la leyenda

Me gustaría agregar un borde negro de 1 mm a mi leyenda generada con PYQgis.

Así (con QGis):
enter image description here

¿Cómo puedo hacerlo?

Aquí está mi código:

# LEGENDA
legend = QgsLayoutItemLegend(layout)

# ESTILO LEGENDA (https://qgis.org/pyqgis/3.10/core/QgsLegendStyle.html)
legend.setStyleFont(QgsLegendStyle.Title, QFont('Lucida Fax', 18))
legend.setStyleFont(QgsLegendStyle.Subgroup, QFont('Lucida Fax', 13, QFont.Bold))
legend.setStyleFont(QgsLegendStyle.SymbolLabel, QFont('Lucida Fax', 11))

Gracias.

Tags:  , ,

Answer

  1. Avatar for davy.ai

    Para agregar un borde negro de 1 mm a su leyenda generada con PYQgis, puede utilizar los métodos setFrameEnabled() y setFrameStrokeWidth() de la clase QgsLayoutItemLegend.

    Aquí hay un ejemplo de código:

    # LEGENDA
    leyenda = QgsLayoutItemLegend(layout)
    
    # ESTILO DE LA LEYENDA (https://qgis.org/pyqgis/3.10/core/QgsLegendStyle.html)
    leyenda.setStyleFont(QgsLegendStyle.Title, QFont('Lucida Fax', 18))
    leyenda.setStyleFont(QgsLegendStyle.Subgroup, QFont('Lucida Fax', 13, QFont.Bold))
    leyenda.setStyleFont(QgsLegendStyle.SymbolLabel, QFont('Lucida Fax', 11))
    
    # Agregar borde negro con un ancho de 1 mm
    leyenda.setFrameEnabled(True)
    leyenda.setFrameStrokeWidth(1)
    
    # Agregar la leyenda al diseño
    layout.addLayoutItem(leyenda)
    

    Esto habilitará el marco de la leyenda y establecerá el ancho del trazo del marco en 1 mm, lo que resultará en un borde negro alrededor de la leyenda.

Comments are closed.