1

When I print my project, that includes different layers, I always end up with all the layers in the legend. What I want when printing is to only show 1 layer, that always has the same name "Werken". The rest of the layers are not necessary to be shown in the legend. What kind of expression would I have to write to become this result? legend as is now

  • You can manually remove layers from the legend by selecting the layer name and clicking the red "minus" button. If you want to filter the legend by expression, please explain what your criteria are. – csk Mar 12 at 20:28
  • @csk I want to only keep the layer named "Werken" in my legend through an expression. The only problem is that I don't know how to do this :) Could you help? – bcallewaert Mar 13 at 10:33
0

Legend filter expressions only apply on a per-layer basis. In other words, you can apply a filter to one layer at a time. You can't apply a filter to all layers in the legend.

enter image description here

So there's no way to use an expression to control which layers are displayed in the legend.


It's quite easy to remove layers you don't want manually. There are two ways:

  1. Select the layers you don't want in the legend, and click the red minus button.
  2. If you have a lot of layers, and have trouble finding the one layer that you want to keep, simply remove all the layers as in step 1. Then click the green plus button, and add the layer you do want.

Once the legend is set up how you want it, you can re-use the same legend in other print layouts.

  • When you create a new print layout in the same project, you can copy and paste the legend from the old print layout into the new layout.
  • Save the print layout as a template. When you open a different project, load the saved template into a blank print layout.

Note: This answer applies to the GUI (graphical user interface) only. It might be possible to solve this problem using pyqgis in the Python Console, but that's outside the scope of the question as it's written. If you want a pyqgis solution, be aware that questions on this site asking for code without including a code snippet will be closed for this reason:

Questions seeking help to debug/write/improve code must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Providing a clear problem statement and evidence of a code attempt will help others to help you. See: How to create a Minimal, Complete, and Verifiable example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.