Beispiel #1
0
def paint_page(painter, page, page_rect):
    """
    Given a `painter` and a `page` (a widget presumably created parsing a
    wreport), renders the widget on the painter and returns a QPicture.
    """
    # make qwidget output vectorial, rendering directly on a printer
    # results in a raster image in the pdf
    page_pic = QPicture()
    wpainter = QPainter(page_pic)

    # set the BoundingRect of page_pic and the page size to page_rect
    page_pic.setBoundingRect(page_rect.toRect())
    page.resize(page_rect.toRect().width(), page_rect.toRect().height())

    page.render(wpainter, flags=QWidget.DrawChildren)
    wpainter.end()
    painter.drawPicture(0, 0, page_pic)
    return page_pic
Beispiel #2
0
from PyQt5.QtCore import QRect, QRectF, QSizeF, QPointF, Qt
from PyQt5.QtGui import QPainter, QPicture, QFont, QColor
from PyQt5.QtWidgets import QApplication, QLabel

def drawNode(painter, angle, radius, text):
    size = 32767.0;
    painter.save();
    painter.rotate(-angle);
    painter.translate(radius, 0);
    painter.drawText(QRectF(0, -size/2.0, size, size), Qt.AlignVCenter, text);
    painter.restore();

if __name__ == "__main__":
    app = QApplication(sys.argv)

    pic = QPicture()
    pic.setBoundingRect(QRect(-100, -100, 200, 200))
    p = QPainter(pic)

    p.drawEllipse(0, 0, 3, 3)
    p.setFont(QFont("Helvetica", 25))
    for angle in range(0, 359, 30):
        drawNode(p, angle, 50, str(angle))
    p.end()

    l = QLabel()
    l.setPicture(pic);
    l.show();

    sys.exit(app.exec_())