I am looking for a way to add a picture to my map using pyqgis. Are there any examples of how to do this. I know it can be done using the classQgsComposerPicture. I am not much of a programmer so I cannot decode the api documentation. Any links where I can find such examples or documentation with options.
Answer
If I want to add an icon QGIS logo (111 pixels x 111 pixels) to my composer map, the snipped code that it works is:
.
.
.
#Initialize the picture object
logo = QgsComposerPicture(c) #c is a QgsComposition object
logo.setPictureFile("/home/zeito/pyqgis_data/qgis-icon_21.png")
logo.setSceneRect(QRectF(0,0,40,40)) #Resize logo
logo. setItemPosition(20,20)
c.addItem(logo)
.
.
.
The result is:
With this QRectF(0,0,20,20) object I have:
I have to use the 'setSceneRect' method of QgsComposerPicture class.
No comments:
Post a Comment