Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QBrush transformation ignored by QPrinter/QPdfWriter
Forum Updated to NodeBB v4.3 + New Features

QBrush transformation ignored by QPrinter/QPdfWriter

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 2 Posters 1.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bordaigorl
    wrote on last edited by bordaigorl
    #1

    I am trying to produce a PDF from a QGraphicsScene.
    I am drawing some paths with a brush that has a pixmap texture, and a scale transformation applied (with brush.setTransform).
    When I display the scene in a QGraphicsView I get exactly the desired output.
    When I render the same scene to a QPrinter (set to produce a pdf) the texture is applied but ignoring the transformation.
    Is this a known limitation? Is there a way around it?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Which version of Qt are you using ?
      On which platform ?
      Can you provide a minimal compilable example that shows that behaviour ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • B Offline
        B Offline
        bordaigorl
        wrote on last edited by
        #3

        Hi! I am using PyQt 5.15.2 (Qt 5.15.2) on macOs 10.15.7.

        Below is a minimal example showing the problem in a context similar to my use case.
        Here I am creating a texture on the fly for illustration purposes.
        The rendering artifacts due to antialiasing are irrelevant for my question.
        The issue is the discrepancy between the scale (set at .2) of the texture in the rendered brush and the scale (always 1) in the pdf output.
        [To generate the output just double click on the view, you'll see a test.pdf in the current path.]

        from PyQt5.QtCore import *
        from PyQt5.QtGui import *
        from PyQt5.QtWidgets import *
        from PyQt5.QtPrintSupport import *
        
        class Test(QGraphicsView):
        
          def __init__(self):
            QGraphicsView.__init__(self)
        
            tr = QTransform()
            tr.scale(.2,.2)
            s = 50
            img = QImage(s, s, QImage.Format_ARGB32)
            img.fill(Qt.transparent)
            for x in range(s):
              img.setPixelColor(x,0,Qt.black)
              img.setPixelColor(x,s-1,Qt.black)
              img.setPixelColor(s-1,x,Qt.black)
              img.setPixelColor(0,x,Qt.black)
        
            self.scene = QGraphicsScene()
            self.setScene(self.scene)
            r = self.scene.addRect(0, 0, 1404, 1872)
        
            pen = QPen()
            pen.setWidth(150)
            pen.setCapStyle(Qt.RoundCap)
            pen.setJoinStyle(Qt.RoundJoin)
            b=QBrush(img)
            b.setTransform(tr)
            pen.setBrush(b)
        
            path = QPainterPath(QPointF(200, 200))
            path.lineTo(300,300)
            path.lineTo(300,1000)
            path.lineTo(700,700)
            self.pathItem = QGraphicsPathItem(path, r)
            self.pathItem.setPen(pen)
        
          def resizeEvent(self, event):
            self.fitInView(self.sceneRect(), Qt.KeepAspectRatio)
        
          def mouseDoubleClickEvent(self, event):
            printer = QPrinter(QPrinter.HighResolution)
            printer.setOutputFormat(QPrinter.PdfFormat)
            # printer.setPageSize(QPrinter.A4)
            printer.setOutputFileName("test.pdf")
            printer.setPaperSize(QSizeF(1404,1872), QPrinter.Millimeter)
            printer.setPageMargins(0,0,0,0, QPrinter.Millimeter)
            p=QPainter()
            p.begin(printer)
            self.scene.render(p)
            p.end()
        
        if __name__ == '__main__':
          app = QApplication([])
          print(QT_VERSION_STR)
          print(PYQT_VERSION_STR)
          viewer = Test()
          viewer.show()
          app.exec_()
        
        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Looks like you may have found something. Did you already check the bug report system ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • B Offline
            B Offline
            bordaigorl
            wrote on last edited by
            #5

            A quick search in the bug report system returned nothing related...

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Did you also test with PySide2/6 ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              B 1 Reply Last reply
              0
              • SGaistS SGaist

                Did you also test with PySide2/6 ?

                B Offline
                B Offline
                bordaigorl
                wrote on last edited by
                #7

                I did not test this with PySide myself, but another dev confirmed this problem when using PySide2 (5.14.2) to do something very similar. I'd be very surprised if this was caused by the python bindings and not by Qt itself...

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Since these bindings are usually provided with different builds of Qt there might have been one that was working. Since it's reproducible with PySide2 it's one more reason to open a bug report with your minimal example.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved