2

I need help in adding a label to QGIS map composer through python script. I could add a label but it is incomplete. The label is like this: 27-02-15 11-25. It only shows the first part: 27-02-15. I don't know why.

Also when I create the composer map, the other elements were put outside of the composer map rectangle. It is possible to overlap elements in map composer?

EDIT I see that the problem is in the width and height of label box. I can't find a way of change this parameters. The adjustSizeToText should do it, but somehow is not doing that.

2
  • What GIS software are you using? – PolyGeo Oct 1 '15 at 20:32
  • I am using QGIS software. – Bárbara Duarte Oct 1 '15 at 21:17
4

Ok. My bad. The error was mine.

The adjustSizeToText must be in the final of the definition of characteristics of the text. Sorry for that. If anyone has this problem, please put the adjustSizeTotext in the end, like this:

title = QgsComposerLabel(myComposition)
title.setText(str(text))
title.setFont(QFont("Cambria",40, QFont.Bold))
title.setItemPosition(185.8,5.2)
title.adjustSizeToText()
myComposition.addItem(title)  

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.