コード例 #1
0
    def __init__(self, parent):
        QPushButton.__init__(self, parent)

        self._cancelled = False
        self._originalColor = None
        self._color = QColor('black')
        self._colorPickerWidget = ColorPickerWidget(self)
        self._colorPickerWidget.setWindowFlags(Qt.Popup)
        self._colorPickerWidget.hide()
        self._colorPickerWidget.installEventFilter(self)
        self._colorPickerWidget.resize(80, 80)
        self.refresh()

        self._colorPickerWidget.colorChanged.connect(self.refresh)
        self.clicked.connect(self.togglePopup)
コード例 #2
0
 def color(self):
     return QColor.fromHsv(self.hue(), self.saturation(), self.lightness(),
                           self.alpha())
コード例 #3
0
 def color( self ):
     return QColor.fromHsv( self.hue(), self.saturation(), self.lightness(), self.alpha() )
コード例 #4
0
    def paintEvent(self, event):
        painter = QPainter()
        painter.begin(self)

        painter.setPen(Qt.black)

        # create the hue rect
        hrect = self.hueRect()

        # create the hue gradient
        grad = QLinearGradient()
        grad.setStart(0, hrect.top())
        grad.setFinalStop(0, hrect.bottom())

        for i in range(10):
            perc = i / 10.0
            grad.setColorAt(perc, QColor.fromHsv(perc * 360, 255, 255))

        grad.setColorAt(1.0, QColor.fromHsv(359, 255, 255))

        painter.setBrush(grad)
        painter.drawRect(hrect)

        # create the hue line
        y = (hrect.y() + 2) + self.huePercent() * (hrect.height() - 3)
        pen = painter.pen()
        pen.setColor(Qt.white)
        pen.setWidth(2)
        painter.setPen(pen)
        painter.drawLine(hrect.left() + 2, y, hrect.right(), y)
        painter.setPen(Qt.black)

        # create the alpha rect
        if (self.showAlpha()):
            arect = self.alphaRect()

            # create the alpha gradient
            grad = QLinearGradient()
            grad.setStart(arect.left(), 0)
            grad.setFinalStop(arect.right(), 0)
            grad.setColorAt(0.0, QColor(Qt.black))
            grad.setColorAt(1.0, QColor(Qt.white))
            painter.setBrush(grad)
            painter.drawRect(arect)

            # create the alpha line
            x = (arect.x() +
                 2) + (1 - self.alphaPercent()) * (arect.width() - 3)
            pen = painter.pen()
            pen.setColor(Qt.yellow)
            pen.setWidth(2)
            painter.setPen(pen)
            painter.drawLine(x, arect.top() + 2, x, arect.bottom())
            painter.setPen(Qt.black)

        crect = self.colorRect()

        # create the color scale gradient
        grad = QLinearGradient()
        grad.setStart(crect.left(), 0)
        grad.setFinalStop(crect.right(), 0)
        grad.setColorAt(0.0, QColor(255, 255, 255, self.alpha()))
        grad.setColorAt(1.0, QColor.fromHsv(self.hue(), 255, 255,
                                            self.alpha()))
        painter.setBrush(grad)
        painter.drawRect(crect)

        # create the grayscale gradient
        grad = QLinearGradient()
        grad.setStart(0, crect.top())
        grad.setFinalStop(0, crect.bottom())
        grad.setColorAt(0.0, QColor(0, 0, 0, 0))
        grad.setColorAt(1.0, QColor(0, 0, 0, self.alpha()))
        painter.setBrush(grad)
        painter.drawRect(crect)

        # create the color location
        x = crect.x() + (self.saturation() / 255.0) * crect.width()
        y = crect.y() + (1 - (self.lightness() / 255.0)) * crect.height()

        painter.setPen(Qt.white)
        painter.setBrush(
            QColor.fromHsv(self.hue(), self.saturation(), self.lightness(),
                           50))

        painter.setClipRect(crect)
        painter.setRenderHint(QPainter.Antialiasing)
        painter.drawEllipse(QPoint(x, y), 5, 5)

        painter.end()
コード例 #5
0
    def paintEvent( self, event ):
        painter = QPainter()
        painter.begin( self )

        painter.setPen( Qt.black )

        # create the hue rect
        hrect = self.hueRect()

        # create the hue gradient
        grad = QLinearGradient()
        grad.setStart( 0, hrect.top() )
        grad.setFinalStop( 0, hrect.bottom() )

        for i in range( 10 ):
            perc = i / 10.0
            grad.setColorAt( perc, QColor.fromHsv( perc * 360, 255, 255 ) )

        grad.setColorAt( 1.0, QColor.fromHsv( 359, 255, 255 ) )

        painter.setBrush( grad )
        painter.drawRect( hrect )

        # create the hue line
        y = (hrect.y() + 2) + self.huePercent() * (hrect.height() - 3)
        pen = painter.pen()
        pen.setColor( Qt.white )
        pen.setWidth( 2 )
        painter.setPen( pen )
        painter.drawLine( hrect.left() + 2, y, hrect.right(), y )
        painter.setPen( Qt.black )

        # create the alpha rect
        if ( self.showAlpha() ):
            arect = self.alphaRect()

            # create the alpha gradient
            grad = QLinearGradient()
            grad.setStart( arect.left(), 0 )
            grad.setFinalStop( arect.right(), 0 )
            grad.setColorAt( 0.0, QColor( Qt.black ) )
            grad.setColorAt( 1.0, QColor( Qt.white ) )
            painter.setBrush( grad )
            painter.drawRect( arect )

            # create the alpha line
            x = (arect.x() + 2) + (1 - self.alphaPercent()) * (arect.width() - 3)
            pen = painter.pen()
            pen.setColor( Qt.yellow )
            pen.setWidth( 2 )
            painter.setPen( pen )
            painter.drawLine( x, arect.top() + 2, x, arect.bottom() )
            painter.setPen( Qt.black )

        crect = self.colorRect()

        # create the color scale gradient
        grad = QLinearGradient()
        grad.setStart( crect.left(), 0 )
        grad.setFinalStop( crect.right(), 0 )
        grad.setColorAt( 0.0, QColor( 255, 255, 255, self.alpha() ) )
        grad.setColorAt( 1.0, QColor.fromHsv( self.hue(), 255, 255, self.alpha() ) )
        painter.setBrush( grad )
        painter.drawRect( crect )

        # create the grayscale gradient
        grad = QLinearGradient()
        grad.setStart( 0, crect.top() )
        grad.setFinalStop( 0, crect.bottom() )
        grad.setColorAt( 0.0, QColor( 0, 0, 0, 0 ) )
        grad.setColorAt( 1.0, QColor( 0, 0, 0, self.alpha() ) )
        painter.setBrush( grad )
        painter.drawRect( crect )

        # create the color location
        x = crect.x() + (self.saturation() / 255.0) * crect.width()
        y = crect.y() + (1 - (self.lightness() / 255.0)) * crect.height()

        painter.setPen( Qt.white )
        painter.setBrush( QColor.fromHsv( self.hue(), self.saturation(), self.lightness(), 50) )

        painter.setClipRect( crect )
        painter.setRenderHint( QPainter.Antialiasing )
        painter.drawEllipse( QPoint( x, y ), 5, 5 )

        painter.end()