The expression pre validation sometimes is not working properly in the print composer even if the expression is valid and would work.
Your first expression is evaluated on the layer so get_feature_by_id have no problem to verify the formula result and let you click ok button.
To make it work you have to add the expression without the expression dialogu box. ...
You should use rstyle method of legend. It returns reference to QgsLegendStyle object for legend components. Then, you can add spacing using setMargin function. Documentation for rstyle and setMargin.
legend.rstyle(QgsLegendStyle.Group).setMargin(QgsLegendStyle.Top, 10) # Top side, 10 mm
You need add heading in symbology tab, here is my sample:
click zone_merge layer, open layer properties, click symbology tab
now, click the item for example, VC village commercial,
right click it, choose, "move to heading", choose 'new heading'
Then, you can click others, choose move to heading, .... and so on.
when you save
the legend will ...
As Erik said in comment the attribute table migth suits your needs. The styling option is limited compare to html table but very easy to do it related to your data.
In the layout, go to panel report organaizer and select your group. Then check include header and hit Edit button. It opens a new page that will be included before your group of pages.
In this ...
General advice: try via the QGIS GUI to achieve what you want then see how to implement it in PyQGIS. It's what I've done here.
You do not need to use any code in particular, just using an expression for fill color style is enough.
Without caring about using PyQGIS first, just try manually the following:
On your layer you want to select, just set the fill ...
Make a rectangular polygon the same extent as your layout. I called mine 'limits'
Copy your polygons layer to a new layer, and create a new attribute 'legend' using the attribute calculator. I used this expression:
Then set a query on this layer to:
You should only see the relevant polygons, but the ...
I work on the development team at Esri and wanted to reach out. By default, chart frames in layouts will only show data that is visible in the associated map frame. In cases where the chart frame is not showing the entire dataset (because some data is not visible in the map frame), the r2 will be calculated using only the subset of data that is displayed ...