On Wed, 2 Sep 2020 at 03:39, C Hamilton <[email protected]> wrote: > > I am trying to calculate the size of a single symbol in pixels using: > > canvas = iface.mapCanvas() > context = QgsRenderContext.fromMapSettings(canvas.mapSettings()) > layer = iface.activeLayer() > rnd = layer.renderer() > sym = rnd.symbol() > scaled_size_in_pixels = context.convertToPainterUnits( > sym.size(), > sym.sizeUnit(), > sym.sizeMapUnitScale() ) > > The last line can also be calculated by: > > scaled_size_in_pixels = sym.size(context) > > 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?
You can use QgsSymbolLayerUtils::estimateMaxSymbolBleed if you're wanting to calculate the "maximum" bounding box of a rendered symbol. That includes any stroke/offset/other settings which also affect the rendered bounds. There's also QgsMarkerSymbol::bounds which returns an approximate bounding box of a marker symbol, which also accounts for things like the stroke and offset. Nyall > > Thanks, > > Calvin > > _______________________________________________ > QGIS-Developer mailing list > [email protected] > List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer > Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer _______________________________________________ QGIS-Developer mailing list [email protected] List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
