1

In QGIS 3.34.5 I have a vector layer in QGIS with a large amount of attributes.

I want to generate labels that only show relevant attributes. To do that, I define a PyQGIS function that takes a feature, looks at all attributes and stores the relevant ones in a dict.

Next, I convert the dict to a string with each key, value pair on a separate line.

This works well with a hardcoded dict (to just test the principle):

Label renders correctly with hardcoded dict

Expression builder

Function definitions

This also works well with the actual generated dict, storing the result in a virtual field rather than directly displaying in a label (as I cannot modify the layer source data).

It also works well inside the Expression Builder preview pane:

Function definitions with actual expected behaviour

enter image description here

But if I then click OK, the labels disappear completely and nothing is rendered, while in the Expression Builder, everything still looks fine.

Labels not shown anymore

I'm trying to understand why it doesn't work as expected but have no clue what else to try or where to look.

Any suggestions?

1
  • 3
    Have you tried to force all labels to show in the Rendering (paintbrush) tab of the label settings? Maybe it's because the label is too long (horizontally) and the label engine requires you to allow overlaps, or some other setting in the Placement tab, to show the labels Commented Sep 9, 2024 at 13:34

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.