コード例 #1
0
ファイル: test.py プロジェクト: zwlistu/calibre
def full(p, xmax, ymax):
    p.drawRect(0, 0, xmax, ymax)
    p.drawPolyline(QPoint(0, 0), QPoint(xmax, 0), QPoint(xmax, ymax),
                    QPoint(0, ymax), QPoint(0, 0))
    pp = QPainterPath()
    pp.addRect(0, 0, xmax, ymax)
    p.drawPath(pp)
    p.save()
    for i in range(3):
        col = [0, 0, 0, 200]
        col[i] = 255
        p.setOpacity(0.3)
        p.fillRect(0, 0, xmax/10, xmax/10, QBrush(QColor(*col)))
        p.setOpacity(1)
        p.drawRect(0, 0, xmax/10, xmax/10)
        p.translate(xmax/10, xmax/10)
        p.scale(1, 1.5)
    p.restore()

    # p.scale(2, 2)
    # p.rotate(45)
    p.drawPixmap(0, 0, xmax/4, xmax/4, QPixmap(I('library.png')))
    p.drawRect(0, 0, xmax/4, xmax/4)

    f = p.font()
    f.setPointSize(20)
    # f.setLetterSpacing(f.PercentageSpacing, 200)
    f.setUnderline(True)
    # f.setOverline(True)
    # f.setStrikeOut(True)
    f.setFamily('Calibri')
    p.setFont(f)
    # p.setPen(QColor(0, 0, 255))
    # p.scale(2, 2)
    # p.rotate(45)
    p.drawText(QPoint(xmax/3.9, 30), 'Some—text not By’s ū --- Д AV ff ff')

    b = QBrush(Qt.HorPattern)
    b.setColor(QColor(Qt.blue))
    pix = QPixmap(I('lt.png'))
    w = xmax/4
    p.fillRect(0, ymax/3, w, w, b)
    p.fillRect(xmax/3, ymax/3, w, w, QBrush(pix))
    x, y = 2*xmax/3, ymax/3
    p.drawTiledPixmap(QRectF(x, y, w, w), pix, QPointF(10, 10))

    x, y = 1, ymax/1.9
    g = QLinearGradient(QPointF(x, y), QPointF(x+w, y+w))
    g.setColorAt(0, QColor('#00f'))
    g.setColorAt(1, QColor('#fff'))
    p.fillRect(x, y, w, w, QBrush(g))
コード例 #2
0
ファイル: project_list.py プロジェクト: MoonShineVFX/4drec
    def paintEvent(self, event):
        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing)
        painter.drawPixmap(0, 0, self._pixmap)
        painter.fillRect(self.rect(), self.palette().midlight().color())

        round_path = QPainterPath()
        round_path.addRoundedRect(0, 0, self.width(), self.height(), 5, 5)
        sq_path = QPainterPath()
        sq_path.addRect(0, 0, 10, self.height())
        draw_path = sq_path - round_path
        painter.setPen(Qt.NoPen)
        painter.setBrush(self.palette().dark().color())
        painter.drawPath(draw_path)
コード例 #3
0
ファイル: AppTools.py プロジェクト: zy-sunshine/falkon-pyqt5
    def createPixmapForSite(self, icon, title, url):
        '''
        @param: icon QIcon
        @param: title QString
        @param: url QString
        @return: QPixmap
        '''
        fontMetrics = QApplication.fontMetrics()
        padding = 4
        text = len(title) > len(url) and title or url
        maxWidth = fontMetrics.width(text) + 3 * padding + 16
        width = min(maxWidth, 150)
        height = fontMetrics.height() * 2 + fontMetrics.leading() + 2 * padding

        pixelRatio = gVar.app.devicePixelRatio()
        pixmap = QPixmap(width * pixelRatio, height * pixelRatio)
        pixmap.setDevicePixelRatio(pixelRatio)

        painter = QPainter(pixmap)
        painter.setRenderHint(QPainter.Antialiasing)

        # Draw background
        pen = QPen(Qt.black)
        pen.setWidth(1)
        painter.setPen(pen)

        path = QPainterPath()
        path.addRect(QRectF(0, 0, width, height))

        painter.fillPath(path, Qt.white)
        painter.drawPath(path)

        # Draw icon
        iconRect = QRect(padding, 0, 16, height)
        icon.paint(painter, iconRect)

        # Draw title
        titleRect = QRectF(iconRect.right() + padding, padding,
                width - padding - iconRect.right(), fontMetrics.height())
        painter.drawText(titleRect, fontMetrics.elidedText(title, Qt.ElideRight, titleRect.width()))

        # Draw url
        urlRect = QRectF(titleRect.x(), titleRect.bottom() + fontMetrics.leading(),
                titleRect.width(), titleRect.height())
        painter.setPen(QApplication.palette().color(QPalette.Link))
        painter.drawText(urlRect, fontMetrics.elidedText(url, Qt.ElideRight, urlRect.width()))

        return pixmap