[Qgis-developer] QGis 2.6 python API - remove legend row from a subgroup

Raphael Dubois raphael.dubois at openocean.fr
Fri Feb 20 08:44:40 PST 2015


Hello,

(QGis version 2.6)
I am trying to delete some legend rows with the python API. I works fine 
for the Subgroups but I can't remove the rows inside a Subgroup (the 
Symbols).

This is the legend in the generated .png file, I want to remove the row 
"Less than 50.0".


In my python script (I only have 1 column so the column index is always 0):
/legend = qgs.core.QgsComposerLegend(composer)/
/subgroup = legend.modelV2().index(0, 0) # Grabs my first subgroup in 
the legend, "Bathymetry [m]"//
//legend.modelV2().removeRow(0) # Removes the first subgroup, returns 
True (works)/

Now, I want to remove the first symbol of my second subgroup, 
"Population density [people/km²]" - the first symbol label is "Less than 
50.0"
First, I grab the QModelIndex of the row I want to delete, to verify 
it's the good one.
This time, I didn't remove the "Bathymetry [m]" subgroup from the 
legend, so I access the "Population density" subgroup with the row index 1.
/subgroup = legend.modelV2().index(1, 0)//
//print subgroup.data() # "Population density [people/km²]"//
//symbol = subgroup.child(0, 0)//
//print symbol.data() # "Less than 50.0" => this is the one I want to 
delete/

I tried several methods to remove it, none worked...
/legend.modelV2().removeRow(0, symbol.parent()) # Returns False (doesn't 
work//)
//legend.modelV2().removeRow(0, subgroup) # Returns False (doesn't work/)
Same with /removeRows(0, 1, symbol.parent())/...
I also tried to remove other rows from this subgroup, and it never worked.

Am I doing something wrong ? Do you have a hint on how I should proceed 
to remove this ?

Thank you,
-- 
Raphaël Dubois
Project Engineer
Open Ocean SAS
27 rue du Chemin Vert
75011 Paris
+33(0)9 7239 0165

raphael.dubois at openocean.fr <mailto:raphael.dubois at openocean.fr>
http://www.openocean.fr
<http://www.openocean.fr>



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20150220/963be9d3/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ghifgffg.png
Type: image/png
Size: 26588 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20150220/963be9d3/attachment-0001.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: open-ocean.gif
Type: image/gif
Size: 5361 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20150220/963be9d3/attachment-0001.gif>


More information about the Qgis-developer mailing list