1

I add to the composer an attribute table and in this table there is no content.

My Code:

    mapRenderer = self.iface.mapCanvas().mapRenderer()
    c = QgsComposition(mapRenderer)
    c.setPlotStyle(QgsComposition.Print)
    x, y = 0, 0
    w, h = c.paperWidth(), c.paperHeight()
    composerMap = QgsComposerMap(c, x,y,w,h)
    c.addItem(composerMap)

    composerLabel = QgsComposerLabel(c)
    composerLabel.setText("Hello world")
    composerLabel.adjustSizeToText()
    c.addItem(composerLabel)

    tableGes = QgsComposerAttributeTable(c)
    tableGes.setVectorLayer(vlayer)
    tableGes.setComposerMap(composerMap)
    tableGes.setDisplayOnlyVisibleFeatures(True)
    c.addItem(tableGes)
    ## Here i try this Methode also:
    ##c.addComposerTable(tableGes)
    ## Same result!

    printer = QPrinter()
    printer.setOutputFormat(QPrinter.PdfFormat)
    printer.setOutputFileName("E:\***\out.pdf")
    printer.setPaperSize(QSizeF(c.paperWidth(), c.paperHeight()),
    QPrinter.Millimeter)
    printer.setFullPage(True)
    printer.setColorMode(QPrinter.Color)
    printer.setResolution(150)

    pdfPainter = QPainter(printer)
    c.renderPage(pdfPainter, 0)
    pdfPainter.end()

Additional I post the out.pdf as a image.

enter image description here

Can someone try the code in their own plugin?

If there is the same result i can make a bug report.

If not, I need to search for the bug in my plugin.

  • Are you using QGIS stable (2.0) or Master/Dev (2.1)? – James S Nov 4 '13 at 9:14
  • I try it in 2.0 and 2.1 ... – Andreas P Nov 4 '13 at 9:56
  • Is the CRS of the project and the layer the same / correct? – Willy Nov 4 '13 at 11:05
  • I check it ... yes it is the same crs ... – Andreas P Nov 4 '13 at 15:50
  • have you tried setting the projection of the map renderer? myMapRenderer.setProjectionsEnabled( True ) crs = QgsCoordinateReferenceSystem() crs.createFromSrid( 32632 ) myMapRenderer.setDestinationCrs( crs ) – James S Nov 6 '13 at 14:20
2

It was a bug and it is fixed upstream f867506 It will be part of QGIS 2.2 and 2.0.2

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.