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


Python QImage.rect方法代码示例

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


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

示例1: drawIconWithShadow

# 需要导入模块: from PySide.QtGui import QImage [as 别名]
# 或者: from PySide.QtGui.QImage import rect [as 别名]
    def drawIconWithShadow(icon, rect, p, iconMode, radius, color, offset):
        cache = QPixmap()
        pixmapName = "icon {0} {1} {2}".format(icon.cacheKey(), iconMode, rect.height())

        if not QPixmapCache.find(pixmapName, cache):
            px = icon.pixmap(rect.size())
            cache = QPixmap(px.size() + QSize(radius * 2, radius * 2))
            cache.fill(Qt.transparent)

            cachePainter = QPainter(cache)
            if iconMode == QIcon.Disabled:
                im = px.toImage().convertToFormat(QImage.Format_ARGB32)
                for y in range(im.height()):
                    scanLine = im.scanLine(y)
                    for x in range(im.width()):
                        pixel = scanLine
                        intensity = qGray(pixel)
                        scanLine = qRgba(intensity, intensity, intensity, qAlpha(pixel))
                        scanLine += 1
                px = QPixmap.fromImage(im)

            # Draw shadow
            tmp = QImage(px.size() + QSize(radius * 2, radius * 2 + 1), QImage.Format_ARGB32_Premultiplied)
            tmp.fill(Qt.transparent)

            tmpPainter = QPainter(tmp)
            tmpPainter.setCompositionMode(QPainter.CompositionMode_Source)
            tmpPainter.drawPixmap(QPoint(radius, radius), px)
            tmpPainter.end()

            # blur the alpha channel
            blurred = QImage(tmp.size(), QImage.Format_ARGB32_Premultiplied)
            blurred.fill(Qt.transparent)
            blurPainter = QPainter(blurred)
            # todo : blur image
            blurPainter.end()

            tmp = blurred

            # blacken the image
            tmpPainter.begin(tmp)
            tmpPainter.setCompositionMode(QPainter.CompositionMode_SourceIn)
            tmpPainter.fillRect(tmp.rect(), color)
            tmpPainter.end()

            tmpPainter.begin(tmp)
            tmpPainter.setCompositionMode(QPainter.CompositionMode_SourceIn)
            tmpPainter.fillRect(tmp.rect(), color)
            tmpPainter.end()

            # draw the blurred drop shadow...
            cachePainter.drawImage(QRect(0, 0, cache.rect().width(), cache.rect().height()), tmp)

            # Draw the actual pixmap...
            cachePainter.drawPixmap(QPoint(radius, radius) + offset, px)
            QPixmapCache.insert(pixmapName, cache)

        targetRect = cache.rect()
        targetRect.moveCenter(rect.center())
        p.drawPixmap(targetRect.topLeft() - offset, cache)
开发者ID:nichollyn,项目名称:libspark,代码行数:62,代码来源:stylehelper.py

示例2: SetImageTransparency

# 需要导入模块: from PySide.QtGui import QImage [as 别名]
# 或者: from PySide.QtGui.QImage import rect [as 别名]
def SetImageTransparency(image, transparencyPercentage):
    """ Set the Image Transparency to the value provided """
    alpha = QImage(image)
    painter = QPainter(alpha)
    alphaValue = int(transparencyPercentage*255/100)
    painter.fillRect(alpha.rect(), QColor(alphaValue, alphaValue, alphaValue))
    painter.end()
    image.setAlphaChannel(alpha)
开发者ID:cloew,项目名称:PyMine,代码行数:10,代码来源:image_loader.py

示例3: addUnit

# 需要导入模块: from PySide.QtGui import QImage [as 别名]
# 或者: from PySide.QtGui.QImage import rect [as 别名]
    def addUnit(self, unit):
        global mapSize
        unit.tile = self
        self.units.append(unit)
        img = QImage(unit.image).scaledToWidth(self.getImageRect().width())
        if unit.owner:
            rect = img.rect()
            painter = QPainter(img)
            painter.setPen(unit.owner.unitColor())
            painter.drawEllipse(rect)

            hpWidth = 20
            greenWidth = unit.hp / float(unit.maxHp) * hpWidth
            painter.fillRect(5, 5, greenWidth, 5, Qt.green)
            painter.fillRect(5 + greenWidth, 5, hpWidth-greenWidth, 5, Qt.red)
            painter.end()
        image = QGraphicsPixmapItem(QPixmap(img), self)
        if mapSize == 0:
            mapSize = 1
        image.setOffset(self.x + 12/(2*mapSize), self.y + 10/(2*mapSize))
        self.unitImages.append(image)
开发者ID:Odingod,项目名称:Vuoropohjainen-peli,代码行数:23,代码来源:Hexagon.py


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