As I get more into QGIS scripting, I refer to the documentation often and usually without success. I have trouble deciphering how to interpret the classes, etc.

I found this thread which is really the same question and it helps a bit but I am still confused.

Let's take the QgsLayoutItemLegend class for example from the documentation:

Now, I think I understand that in order to create a legend item and add it to my Print Layout, I would do something like this...


In the QGIS python editor I am prompted to include arguments for the function, which is helpful. It looks like this: enter image description here

I look in the documentation for the QgsLayoutItemLegend.create() method and see this below, which I cannot make sense of: enter image description here

I see nothing about the arguments this method takes in the documentation.

How do I create a Legend using QgsLayoutItemLegend?


You create it directly, using the layout as the only argument:


Then you must add the newly created item to the layout (this isn't done automatically):

| improve this answer | |

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.