Skip to main content
added 41 characters in body
Source Link
Taras
  • 33.3k
  • 4
  • 68
  • 139

You can use the setStyleFont()setStyleFont() method of the QgsLayoutItemLegend class. The first argument is a component, so you need to pass a QgsLegendStyle::StyleQgsLegendStyle::Style enumerator item, e.g. QgsLegendStyle.Title, QgsLegendStyle.SymbolLabel etc.

Example snippet:

item_font = QFont('Arial', 14)
legend_item.setStyleFont(QgsLegendStyle.SymbolLabel, item_font)
legend_item.refresh()

Note that according to the docs, this method is deprecated and from version 3.30 onwards, you should

use QgsLegendStyle::setTextFormat()QgsLegendStyle::setTextFormat() from style()style() instead.

Example below. FYI, with this approach I found it necessary to add a call to legend_item.setStyleMargin() because, for some reason, the space between the symbol and label is lost which may be a bug, but I don't have time to investigate further right now.

  
# >= 3.30
legend_style = QgsLegendStyle()
text_format = QgsTextFormat()
item_font = QFont('Arial')
text_format.setFont(item_font)
text_format.setSize(14)
legend_style.setTextFormat(text_format)
legend_item.setStyle(QgsLegendStyle.SymbolLabel, legend_style)
legend_item.setStyleMargin(QgsLegendStyle.Symbol, QgsLegendStyle.Right, 2.5)
legend_item.refresh()

You can use the setStyleFont() method of the QgsLayoutItemLegend class. The first argument is a component, so you need to pass a QgsLegendStyle::Style enumerator item e.g. QgsLegendStyle.Title, QgsLegendStyle.SymbolLabel etc.

Example snippet:

item_font = QFont('Arial', 14)
legend_item.setStyleFont(QgsLegendStyle.SymbolLabel, item_font)
legend_item.refresh()

Note that according to the docs, this method is deprecated and from version 3.30 onwards, you should

use QgsLegendStyle::setTextFormat() from style() instead.

Example below. FYI, with this approach I found it necessary to add a call to legend_item.setStyleMargin() because, for some reason, the space between the symbol and label is lost which may be a bug but I don't have time to investigate further right now.

 
# >= 3.30
legend_style = QgsLegendStyle()
text_format = QgsTextFormat()
item_font = QFont('Arial')
text_format.setFont(item_font)
text_format.setSize(14)
legend_style.setTextFormat(text_format)
legend_item.setStyle(QgsLegendStyle.SymbolLabel, legend_style)
legend_item.setStyleMargin(QgsLegendStyle.Symbol, QgsLegendStyle.Right, 2.5)
legend_item.refresh()

You can use the setStyleFont() method of the QgsLayoutItemLegend class. The first argument is a component, so you need to pass a QgsLegendStyle::Style enumerator item, e.g. QgsLegendStyle.Title, QgsLegendStyle.SymbolLabel etc.

Example snippet:

item_font = QFont('Arial', 14)
legend_item.setStyleFont(QgsLegendStyle.SymbolLabel, item_font)
legend_item.refresh()

Note that according to the docs, this method is deprecated and from version 3.30 onwards, you should

use QgsLegendStyle::setTextFormat() from style() instead.

Example below. FYI, with this approach I found it necessary to add a call to legend_item.setStyleMargin() because, for some reason, the space between the symbol and label is lost which may be a bug, but I don't have time to investigate further right now.

 
# >= 3.30
legend_style = QgsLegendStyle()
text_format = QgsTextFormat()
item_font = QFont('Arial')
text_format.setFont(item_font)
text_format.setSize(14)
legend_style.setTextFormat(text_format)
legend_item.setStyle(QgsLegendStyle.SymbolLabel, legend_style)
legend_item.setStyleMargin(QgsLegendStyle.Symbol, QgsLegendStyle.Right, 2.5)
legend_item.refresh()
edited body
Source Link
Ben W
  • 21.9k
  • 3
  • 18
  • 41

You can use the setStyleFont() method of the QgsLayoutItemLegend class. The first argument is a component, so you need to pass a QgsLegendStyle::Style enumerator item e.g. QgsLegendStyle.Title, QgsLegendStyle.SymbolLabel etc.

Example snippet:

item_font = QFont('Arial', 14)
legend_item.setStyleFont(QgsLegendStyle.SymbolLabel, item_font)
legend_item.refresh()

Note that according to the docs, this method is deprecated and from version 3.30 onwards, you should

use QgsLegendStyle::setTextFormat() from style() instead.

Example below. FYI, with this approach I found it necessary to add a call to legend_item.setStyleMargin() because, for some reason, the space between the legendsymbol and label is lost which may be a bug but I don't have time to investigate further right now.

# >= 3.30
legend_style = QgsLegendStyle()
text_format = QgsTextFormat()
item_font = QFont('Arial')
text_format.setFont(item_font)
text_format.setSize(14)
legend_style.setTextFormat(text_format)
legend_item.setStyle(QgsLegendStyle.SymbolLabel, legend_style)
legend_item.setStyleMargin(QgsLegendStyle.Symbol, QgsLegendStyle.Right, 2.5)
legend_item.refresh()

You can use the setStyleFont() method of the QgsLayoutItemLegend class. The first argument is a component, so you need to pass a QgsLegendStyle::Style enumerator item e.g. QgsLegendStyle.Title, QgsLegendStyle.SymbolLabel etc.

Example snippet:

item_font = QFont('Arial', 14)
legend_item.setStyleFont(QgsLegendStyle.SymbolLabel, item_font)
legend_item.refresh()

Note that according to the docs, this method is deprecated and from version 3.30 onwards, you should

use QgsLegendStyle::setTextFormat() from style() instead.

Example below. FYI, with this approach I found it necessary to add a call to legend_item.setStyleMargin() because, for some reason, the space between the legend and label is lost which may be a bug but I don't have time to investigate further right now.

# >= 3.30
legend_style = QgsLegendStyle()
text_format = QgsTextFormat()
item_font = QFont('Arial')
text_format.setFont(item_font)
text_format.setSize(14)
legend_style.setTextFormat(text_format)
legend_item.setStyle(QgsLegendStyle.SymbolLabel, legend_style)
legend_item.setStyleMargin(QgsLegendStyle.Symbol, QgsLegendStyle.Right, 2.5)
legend_item.refresh()

You can use the setStyleFont() method of the QgsLayoutItemLegend class. The first argument is a component, so you need to pass a QgsLegendStyle::Style enumerator item e.g. QgsLegendStyle.Title, QgsLegendStyle.SymbolLabel etc.

Example snippet:

item_font = QFont('Arial', 14)
legend_item.setStyleFont(QgsLegendStyle.SymbolLabel, item_font)
legend_item.refresh()

Note that according to the docs, this method is deprecated and from version 3.30 onwards, you should

use QgsLegendStyle::setTextFormat() from style() instead.

Example below. FYI, with this approach I found it necessary to add a call to legend_item.setStyleMargin() because, for some reason, the space between the symbol and label is lost which may be a bug but I don't have time to investigate further right now.

# >= 3.30
legend_style = QgsLegendStyle()
text_format = QgsTextFormat()
item_font = QFont('Arial')
text_format.setFont(item_font)
text_format.setSize(14)
legend_style.setTextFormat(text_format)
legend_item.setStyle(QgsLegendStyle.SymbolLabel, legend_style)
legend_item.setStyleMargin(QgsLegendStyle.Symbol, QgsLegendStyle.Right, 2.5)
legend_item.refresh()
edited body
Source Link
Ben W
  • 21.9k
  • 3
  • 18
  • 41

You can use the setStyleFont() method of the QgsLayoutItemLegend class. The first argument is a component, so you need to pass a QgsLegendStyle::Style enumerator item e.g. QgsLegendStyle.Title, QgsLegendStyle.SymbolLabel etc.

Example snippet:

item_font = QFont('Arial', 1814)
legend_item.setStyleFont(QgsLegendStyle.SymbolLabel, item_font)
legend_item.refresh()

Note that according to the docs, this method is deprecated and from version 3.30 onwards, you should

use QgsLegendStyle::setTextFormat() from style() instead.

Example below. FYI, with this approach I found it necessary to add a call to legend_item.setStyleMargin() because, for some reason, the space between the legend and label is lost which may be a bug but I don't have time to investigate further right now.

# >= 3.30
legend_style = QgsLegendStyle()
text_format = QgsTextFormat()
item_font = QFont('Arial')
text_format.setFont(item_font)
text_format.setSize(1814)
legend_style.setTextFormat(text_format)
legend_item.setStyle(QgsLegendStyle.SymbolLabel, legend_style)
legend_item.setStyleMargin(QgsLegendStyle.Symbol, QgsLegendStyle.Right, 2.5)
legend_item.refresh()

You can use the setStyleFont() method of the QgsLayoutItemLegend class. The first argument is a component, so you need to pass a QgsLegendStyle::Style enumerator item e.g. QgsLegendStyle.Title, QgsLegendStyle.SymbolLabel etc.

Example snippet:

item_font = QFont('Arial', 18)
legend_item.setStyleFont(QgsLegendStyle.SymbolLabel, item_font)
legend_item.refresh()

Note that according to the docs, this method is deprecated and from version 3.30 onwards, you should

use QgsLegendStyle::setTextFormat() from style() instead.

Example below. FYI, with this approach I found it necessary to add a call to legend_item.setStyleMargin() because, for some reason, the space between the legend and label is lost which may be a bug but I don't have time to investigate further right now.

# >= 3.30
legend_style = QgsLegendStyle()
text_format = QgsTextFormat()
item_font = QFont('Arial')
text_format.setFont(item_font)
text_format.setSize(18)
legend_style.setTextFormat(text_format)
legend_item.setStyle(QgsLegendStyle.SymbolLabel, legend_style)
legend_item.setStyleMargin(QgsLegendStyle.Symbol, QgsLegendStyle.Right, 2.5)
legend_item.refresh()

You can use the setStyleFont() method of the QgsLayoutItemLegend class. The first argument is a component, so you need to pass a QgsLegendStyle::Style enumerator item e.g. QgsLegendStyle.Title, QgsLegendStyle.SymbolLabel etc.

Example snippet:

item_font = QFont('Arial', 14)
legend_item.setStyleFont(QgsLegendStyle.SymbolLabel, item_font)
legend_item.refresh()

Note that according to the docs, this method is deprecated and from version 3.30 onwards, you should

use QgsLegendStyle::setTextFormat() from style() instead.

Example below. FYI, with this approach I found it necessary to add a call to legend_item.setStyleMargin() because, for some reason, the space between the legend and label is lost which may be a bug but I don't have time to investigate further right now.

# >= 3.30
legend_style = QgsLegendStyle()
text_format = QgsTextFormat()
item_font = QFont('Arial')
text_format.setFont(item_font)
text_format.setSize(14)
legend_style.setTextFormat(text_format)
legend_item.setStyle(QgsLegendStyle.SymbolLabel, legend_style)
legend_item.setStyleMargin(QgsLegendStyle.Symbol, QgsLegendStyle.Right, 2.5)
legend_item.refresh()
deleted 10 characters in body
Source Link
Ben W
  • 21.9k
  • 3
  • 18
  • 41
Loading
Source Link
Ben W
  • 21.9k
  • 3
  • 18
  • 41
Loading