[Qgis-developer] Get composer item's size and position

Alexander Bruy alexander.bruy at gmail.com
Fri Feb 24 07:24:01 EST 2012


Hi Marco,

thanks for your help. Tried to get composer legend width using
rect().width() and always get 4.0 for different legends. In same
time seems that height is reported correctly. For tests I use
several layers with categorized legend and different number of
classes (from 2 to 40) and next code from Python console

r = qgis.utils.iface.mapCanvas().mapRenderer()
c = QgsComposition( r )
c.setPlotStyle( QgsComposition.Print )
l = QgsComposerLegend( c )
l.model().setLayerSet( r.layerSet() )
print l.rect().width(), l.rect.height()

Any ideas what's wrong?

2012/2/23 Marco Hugentobler <marco.hugentobler at sourcepole.ch>:
> Hi Alex
>
> The methods to get width and height are defined in the parent class
> QGraphicsRectItem. Just use QgsGraphicsItem::rect().width() and
> QGraphicsRectItem::height().
> To set width and height, you may use QgsComposerItem::setItemPosition()
>
> Regards,
> Marco

Thanks
-- 
Alexander Bruy


More information about the Qgis-developer mailing list