I'm using a legend on the left side of the plot and the left and right margins around the legend items are too big. How can I make them smaller?

I need to make them as small as possible as I don't have much space.
I already tried:

legend->contentsWidget()->layout()->setSpacing(0);
legend->contentsWidget()->layout()->setContentsMargins(0,0,0,0);

And it does decrease the spacing between legend items but not the left and right margin.

I don't know if this makes a difference but the legend has so many legend items that it has a vertical scrool bar.

Thanks for the help,
Filipe