<div dir="ltr"><div>Nyall,</div><div><br></div><div>Thanks. This almost gets the right answer. QgsSymbolLayerUtils::estimateMaxSymbolBleed is returning 0 as its value.  I'm not sure what the problem is with it. bounds() seems to work for small symbols which is probably all I'll need, but if the symbol is very large with a large border and join style set to miter, the bounding box it returns is a little too small. My example used an excessively large icon and large border which probably would not be used in any real project.</div><div><br></div><div>Calvin</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Sep 1, 2020 at 6:39 PM Nyall Dawson <<a href="mailto:nyall.dawson@gmail.com">nyall.dawson@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Wed, 2 Sep 2020 at 03:39, C Hamilton <<a href="mailto:adenaculture@gmail.com" target="_blank">adenaculture@gmail.com</a>> wrote:<br>
><br>
> I am trying to calculate the size of a single symbol in pixels using:<br>
><br>
> canvas = iface.mapCanvas()<br>
> context = QgsRenderContext.fromMapSettings(canvas.mapSettings())<br>
> layer = iface.activeLayer()<br>
> rnd = layer.renderer()<br>
> sym = rnd.symbol()<br>
> scaled_size_in_pixels = context.convertToPainterUnits(<br>
>     sym.size(),<br>
>     sym.sizeUnit(),<br>
>     sym.sizeMapUnitScale() )<br>
><br>
> The last line can also be calculated by:<br>
><br>
>   scaled_size_in_pixels = sym.size(context)<br>
><br>
> I am finding that this is returning the size of the filled area of the symbol, but it does not include the border. Is this a bug or do I need to add something additional to include the border?<br>
<br>
You can use  QgsSymbolLayerUtils::estimateMaxSymbolBleed if you're<br>
wanting to calculate the "maximum" bounding box of a rendered symbol.<br>
That includes any stroke/offset/other settings which also affect the<br>
rendered bounds.<br>
<br>
There's also QgsMarkerSymbol::bounds which returns an approximate<br>
bounding box of a marker symbol, which also accounts for things like<br>
the stroke and offset.<br>
<br>
Nyall<br>
<br>
<br>
><br>
> Thanks,<br>
><br>
> Calvin<br>
><br>
> _______________________________________________<br>
> QGIS-Developer mailing list<br>
> <a href="mailto:QGIS-Developer@lists.osgeo.org" target="_blank">QGIS-Developer@lists.osgeo.org</a><br>
> List info: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br>
> Unsubscribe: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br>
</blockquote></div></div>