コード例 #1
0
def save_pdf(widget, filename, preview=False):
    # Creation du printer
    printer = QPrinter()
    file_names = filename
    printer.setOutputFileName(file_names)
    printer.setOutputFormat(QPrinter.PdfFormat)
    printer.setPageMargins(10, 10, 10, 10, QPrinter.Point)

    # Calcul le ratio de redimensionnement
    page_width = printer.pageRect().width()
    page_height = printer.pageRect().height()
    widget_width = widget.width()
    widget_height = widget.height()
    ratio = min(page_width / widget_width, page_height / widget_height)

    # Calcul du positionnement
    pos_x = max(0, (page_width - ratio * widget_width) / 2)
    pos_y = max(0, (page_height - ratio * widget_height) / 2)

    # Render le widget dans une image QPicture pour stocker
    # les directives de dessin
    picture = QPicture()
    widget_painter = QPainter(picture)
    widget_painter.scale(ratio, ratio)
    widget.render(widget_painter)
    widget_painter.end()

    # Render la QPicture en utilisant le QPrinter
    picture_painter = QPainter()
    picture_painter.begin(printer)
    picture_painter.drawPicture(QPointF(pos_x, pos_y), picture)
    picture_painter.end()

    if preview:
        affiche_pdf(file_names)
コード例 #2
0
    def impression(self):
        # Creation du printer
        printer = QPrinter()
        dialog = QPrintDialog(printer, self)
        if dialog.exec_() != QDialog.Accepted:
            return
        printer.setPageMargins(10, 10, 10, 10, QPrinter.Point)

        # Calcul le ratio de redimensionnement
        page_width = printer.pageRect().width()
        page_height = printer.pageRect().height()
        widget_width = self.rapport.width()
        widget_height = self.rapport.height()
        ratio = min(page_width / widget_width, page_height / widget_height)

        # Calcul du positionnement
        pos_x = max(0, (page_width - ratio * widget_width) / 2)
        pos_y = max(0, (page_height - ratio * widget_height) / 2)

        # Render le widget dans une image QPicture pour stocker
        # les directives de dessin
        picture = QPicture()
        widget_painter = QPainter(picture)
        widget_painter.scale(ratio, ratio)
        self.rapport.render(widget_painter)
        widget_painter.end()

        # Render la QPicture en utilisant le QPrinter
        picture_painter = QPainter()
        picture_painter.begin(printer)
        picture_painter.drawPicture(QPointF(pos_x, pos_y), picture)
        picture_painter.end()
コード例 #3
0
    def render_from_z_mask(z_buf_mask, context):
        z_buf_mask = convert_deep_to_alpha(z_buf_mask)
        # рисовать
        qp = QPainter()
        picture = QPicture()

        qp.begin(picture)
        for x in range(len(z_buf_mask)):
            for y in range(len(z_buf_mask[0])):

                # a = color_mask[x][y]
                a = QColor(Qt.black)
                a.setAlpha(z_buf_mask[x][y])

                qp.setPen(a)
                qp.drawPoint(x, y)
        qp.end()  # painting done
        picture.save("drawing.pic")  # save picture

        picture = QPicture()
        picture.load("drawing.pic")  # load picture
        qp = QPainter()
        qp.begin(context)  # paint in myImage
        qp.drawPicture(0, 0, picture)  # draw the picture at (0,0)
        qp.end()
コード例 #4
0
ファイル: lwidget.py プロジェクト: ax-rwnd/lparser-python
 def paintEvent(self, event):
     if self.picture == None:
         print("Warning: picture not yet rendered")
     else:
         qp = QPainter()
         qp.begin(self)
         qp.drawPicture(self.xpos, self.ypos, self.picture)
         qp.end()
コード例 #5
0
    def paint(self, p: QPainter, *args) -> None:
        """
        Method to paint this Widget

        :param p: The painter to paint this widget with
        :return: None
        """
        p.drawPicture(0, 0, self.picture)
コード例 #6
0
 def paint(self, painter: QtGui.QPainter, options, widget=None):
     """
     Starts painting the rectangle.
     :param painter: the QPainter object.
     :param options: options to pass to the painter (actually ignored).
     :param widget: widget to use with the painter (actually ignored)
     """
     painter.drawPicture(0, 0, self.picture)
コード例 #7
0
    def render_from_color_mask(color_mask, context):
        qp = QPainter()
        picture = QPicture()

        qp.begin(picture)
        for x in range(len(color_mask)):
            for y in range(len(color_mask[0])):

                a = color_mask[x][y]
                qp.setPen(a)
                qp.drawPoint(x, y)
        qp.end()  # painting done
        picture.save("drawing.pic")  # save picture

        picture = QPicture()
        picture.load("drawing.pic")  # load picture
        qp = QPainter()
        qp.begin(context)  # paint in myImage
        qp.drawPicture(0, 0, picture)  # draw the picture at (0,0)
        qp.end()