当前位置: 首页>>代码示例>>Python>>正文


Python QPainter.drawPolygon方法代码示例

本文整理汇总了Python中PySide.QtGui.QPainter.drawPolygon方法的典型用法代码示例。如果您正苦于以下问题:Python QPainter.drawPolygon方法的具体用法?Python QPainter.drawPolygon怎么用?Python QPainter.drawPolygon使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PySide.QtGui.QPainter的用法示例。


在下文中一共展示了QPainter.drawPolygon方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: drawArrow

# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import drawPolygon [as 别名]
    def drawArrow(element, painter, option):
        # From windows style but modified to enable AA
        if option.rect.width() <= 1 or option.rect.height() <= 1:
            return

        r = option.rect
        size = min(r.height(), r.width())
        pixmap = QPixmap()
        pixmapName = "arrow-{0}-{1}-{2}-{3}-{4}".format(
            "$qt_ia", int(option.state), element, size, option.palette.cacheKey()
        )
        if not QPixmapCache.find(pixmapName, pixmap):
            border = size / 5
            sqsize = 2 * (size / 2)
            image = QImage(sqsize, sqsize, QImage.Format_ARGB32)
            image.fill(Qt.transparent)
            imagePainter = QPainter(image)
            imagePainter.setRenderHint(QPainter.Antialiasing, True)
            imagePainter.translate(0.5, 0.5)
            a = QPolygon()
            if element == QStyle.PE_IndicatorArrowUp:
                a.setPoints(3, border, sqsize / 2, sqsize / 2, border, sqsize - border, sqsize / 2)
            elif element == QStyle.PE_IndicatorArrowDown:
                a.setPoints(3, border, sqsize / 2, sqsize / 2, sqsize - border, sqsize - border, sqsize / 2)
            elif element == QStyle.PE_IndicatorArrowRight:
                a.setPoints(3, sqsize - border, sqsize / 2, sqsize / 2, border, sqsize / 2, sqsize - border)
            elif element == QStyle.PE_IndicatorArrowLeft:
                a.setPoints(3, border, sqsize / 2, sqsize / 2, border, sqsize / 2, sqsize - border)
            else:
                pass

        bsx = 0
        bsy = 0

        if option.state & QStyle.State_Sunken:
            bsx = qApp.style().pixelMetric(QStyle.PM_ButtonShiftHorizontal)
            bsy = qApp.style().pixelMetric(QStyle.PM_ButtonShiftVertical)

        bounds = a.boundingRect()
        sx = sqsize / 2 - bounds.center().x() - 1
        sy = sqsize / 2 - bounds.center().y() - 1
        imagePainter.translate(sx + bsx, sy + bsy)

        if not (option.state & QStyle.State_Enabled):
            imagePainter.setBrush(option.palette.mid().color())
            imagePainter.setPen(option.palette.mid().color())
        else:
            shadow = QColor(0, 0, 0, 100)
            imagePainter.translate(0, 1)
            imagePainter.setPen(shadow)
            imagePainter.setBrush(shadow)
            foreGround = QColor(255, 255, 255, 210)
            imagePainter.drawPolygon(a)
            imagePainter.translate(0, -1)
            imagePainter.setPen(foreGround)
            imagePainter.setBrush(foreGround)

        imagePainter.drawPolygon(a)
        imagePainter.end()
        pixmap = QPixmap.fromImage(image)
        QPixmapCache.insert(pixmapName, pixmap)

        xOffset = r.x() + (r.width() - size) / 2
        yOffset = r.y() + (r.height() - size) / 2
        painter.drawPixmap(xOffset, yOffset, pixmap)
开发者ID:nichollyn,项目名称:libspark,代码行数:67,代码来源:stylehelper.py

示例2: QPainterDrawText

# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import drawPolygon [as 别名]
class QPainterDrawText(unittest.TestCase):

    def setUp(self):
        self.painter = QPainter()
        self.text = 'teste!'

    def tearDown(self):
        del self.text
        del self.painter

    def testDrawText(self):
        # bug #254
        rect = self.painter.drawText(100, 100, 100, 100,
                                     Qt.AlignCenter | Qt.TextWordWrap,
                                     self.text)
        self.assert_(isinstance(rect, QRect))

    def testDrawTextWithRect(self):
        # bug #225
        rect = QRect(100, 100, 100, 100)
        newRect = self.painter.drawText(rect, Qt.AlignCenter | Qt.TextWordWrap,
                                        self.text)

        self.assert_(isinstance(newRect, QRect))

    def testDrawTextWithRectF(self):
        '''QPainter.drawText(QRectF, ... ,QRectF*) inject code'''
        rect = QRectF(100, 52.3, 100, 100)
        newRect = self.painter.drawText(rect, Qt.AlignCenter | Qt.TextWordWrap,
                                        self.text)

        self.assert_(isinstance(newRect, QRectF))

    def testDrawOverloads(self):
        '''Calls QPainter.drawLines overloads, if something is
           wrong Exception and chaos ensues. Bug #395'''
        self.painter.drawLines([QLine(QPoint(0,0), QPoint(1,1))])
        self.painter.drawLines([QPoint(0,0), QPoint(1,1)])
        self.painter.drawLines([QPointF(0,0), QPointF(1,1)])
        self.painter.drawLines([QLineF(QPointF(0,0), QPointF(1,1))])
        self.painter.drawPoints([QPoint(0,0), QPoint(1,1)])
        self.painter.drawPoints([QPointF(0,0), QPointF(1,1)])
        self.painter.drawConvexPolygon([QPointF(10.0, 80.0),
                                        QPointF(20.0, 10.0),
                                        QPointF(80.0, 30.0),
                                        QPointF(90.0, 70.0)])
        self.painter.drawConvexPolygon([QPoint(10.0, 80.0),
                                        QPoint(20.0, 10.0),
                                        QPoint(80.0, 30.0),
                                        QPoint(90.0, 70.0)])
        self.painter.drawPolygon([QPointF(10.0, 80.0),
                                  QPointF(20.0, 10.0),
                                  QPointF(80.0, 30.0),
                                  QPointF(90.0, 70.0)])
        self.painter.drawPolygon([QPoint(10.0, 80.0),
                                  QPoint(20.0, 10.0),
                                  QPoint(80.0, 30.0),
                                  QPoint(90.0, 70.0)])
        self.painter.drawPolyline([QPointF(10.0, 80.0),
                                   QPointF(20.0, 10.0),
                                   QPointF(80.0, 30.0),
                                   QPointF(90.0, 70.0)])
        self.painter.drawPolyline([QPoint(10.0, 80.0),
                                   QPoint(20.0, 10.0),
                                   QPoint(80.0, 30.0),
                                   QPoint(90.0, 70.0)])
开发者ID:Hasimir,项目名称:PySide,代码行数:68,代码来源:qpainter_test.py


注:本文中的PySide.QtGui.QPainter.drawPolygon方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。