def brushChanged(self): style = QtCore.Qt.BrushStyle( int( self.brushStyleComboBox.itemData( self.brushStyleComboBox.currentIndex(), IdRole))) if style == QtCore.Qt.LinearGradientPattern: linearGradient = QtGui.QLinearGradient(0, 0, 100, 100) linearGradient.setColorAt(0.0, QtCore.Qt.white) linearGradient.setColorAt(0.2, QtCore.Qt.green) linearGradient.setColorAt(1.0, QtCore.Qt.black) self.renderArea.setBrush(QtGui.QBrush(linearGradient)) elif style == QtCore.Qt.RadialGradientPattern: radialGradient = QtGui.QRadialGradient(50, 50, 50, 50, 50) radialGradient.setColorAt(0.0, QtCore.Qt.white) radialGradient.setColorAt(0.2, QtCore.Qt.green) radialGradient.setColorAt(1.0, QtCore.Qt.black) self.renderArea.setBrush(QtGui.QBrush(radialGradient)) elif style == QtCore.Qt.ConicalGradientPattern: conicalGradient = QtGui.QConicalGradient(50, 50, 150) conicalGradient.setColorAt(0.0, QtCore.Qt.white) conicalGradient.setColorAt(0.2, QtCore.Qt.green) conicalGradient.setColorAt(1.0, QtCore.Qt.black) self.renderArea.setBrush(QtGui.QBrush(conicalGradient)) elif style == QtCore.Qt.TexturePattern: self.renderArea.setBrush( QtGui.QBrush(QtGui.QPixmap(":/images/brick.png"))) else: self.renderArea.setBrush(QtGui.QBrush(QtCore.Qt.green, style))
def draw(self, painter): triangle = [ QtCore.QPoint(-2, -49), QtCore.QPoint(+2, -49), QtCore.QPoint(0, -47) ] thickPen = QtGui.QPen(self.palette().foreground(), 1.5) thinPen = QtGui.QPen(self.palette().foreground(), 0.5) niceBlue = QtGui.QColor(150, 150, 200) painter.setPen(thinPen) painter.setBrush(self.palette().foreground()) painter.drawPolygon(QtGui.QPolygon(triangle)) coneGradient = QtGui.QConicalGradient(0, 0, -90.0) coneGradient.setColorAt(0.0, QtCore.Qt.darkGray) coneGradient.setColorAt(0.2, niceBlue) coneGradient.setColorAt(0.5, QtCore.Qt.white) coneGradient.setColorAt(1.0, QtCore.Qt.darkGray) painter.setBrush(coneGradient) painter.drawEllipse(-46, -46, 92, 92) haloGradient = QtGui.QRadialGradient(0, 0, 20, 0, 0) haloGradient.setColorAt(0.0, QtCore.Qt.lightGray) haloGradient.setColorAt(0.8, QtCore.Qt.darkGray) haloGradient.setColorAt(0.9, QtCore.Qt.white) haloGradient.setColorAt(1.0, QtCore.Qt.black) painter.setPen(QtCore.Qt.NoPen) painter.setBrush(haloGradient) painter.drawEllipse(-20, -20, 40, 40) knobGradient = QtGui.QLinearGradient(-7, -25, 7, -25) knobGradient.setColorAt(0.0, QtCore.Qt.black) knobGradient.setColorAt(0.2, niceBlue) knobGradient.setColorAt(0.3, QtCore.Qt.lightGray) knobGradient.setColorAt(0.8, QtCore.Qt.white) knobGradient.setColorAt(1.0, QtCore.Qt.black) painter.rotate(self.duration() * self.DegreesPerSecond) painter.setBrush(knobGradient) painter.setPen(thinPen) painter.drawRoundRect(-7, -25, 14, 50, 99, 49) for i in range(0, self.MaxMinutes + 1): painter.save() painter.rotate(-i * self.DegreesPerMinute) if i % 5 == 0: painter.setPen(thickPen) painter.drawLine(0, -41, 0, -44) painter.drawText(-15, -41, 30, 30, QtCore.Qt.AlignHCenter | QtCore.Qt.AlignTop, str(i)) else: painter.setPen(thinPen) painter.drawLine(0, -42, 0, -44) painter.restore()
def initUI(self): self._conicalGradient = QtGui.QConicalGradient(self.width() / 2, self.height() / 2, 180) for pos, (r, g, b) in CONICAL_GRADIENT: self._conicalGradient.setColorAt(pos, QtGui.QColor(r, g, b)) top = self._rect.top() bottom = self._rect.top() + self._rect.height() self._vertical_gradient = QtGui.QLinearGradient(0, top, 0, bottom) self._vertical_gradient.setColorAt(0.0, QtGui.QColor(*TRANSPARENT)) self._vertical_gradient.setColorAt(1.0, QtGui.QColor(BLACK)) left = self._rect.left() right = self._rect.left() + self._rect.width() self._horizontal_gradient = QtGui.QLinearGradient(left, 0, right, 0) self._horizontal_gradient.setColorAt(0.0, QtGui.QColor(WHITE))
def __init__(self, parent=None): super(ColorWheel, self).__init__(parent) self._is_clicked = False self._rect = QtCore.QRect(25, 25, 50, 50) self._current_color = QtGui.QColor(WHITE) self._color_point = QtCore.QPoint(150, 50) self._current_tool = None self._angle = 180 self.setFixedSize(100, 100) self._conicalGradient = QtGui.QConicalGradient(self.width() / 2, self.height() / 2, 180) for pos, (r, g, b) in CONICAL_GRADIENT: self._conicalGradient.setColorAt(pos, QtGui.QColor(r, g, b)) top = self._rect.top() bottom = self._rect.top() + self._rect.height() self._vertical_gradient = QtGui.QLinearGradient(0, top, 0, bottom) self._vertical_gradient.setColorAt(0.0, QtGui.QColor(*TRANSPARENT)) self._vertical_gradient.setColorAt(1.0, QtGui.QColor(BLACK)) left = self._rect.left() right = self._rect.left() + self._rect.width() self._horizontal_gradient = QtGui.QLinearGradient(left, 0, right, 0) self._horizontal_gradient.setColorAt(0.0, QtGui.QColor(WHITE))
def __init__(self, centerX=0, centerY=0, angle=0, alpha=1): super(ConicalGradientColor, self).__init__(alpha) self.value = QtGui.QConicalGradient(centerX, centerY, angle)