def drawColorBar(self, painter, rect): h1, s1, v1, _ = self.__light.getHsv() h2, s2, v2, _ = self.__dark.getHsv() painter.save() painter.setClipRect(rect) painter.setClipping(True) painter.fillRect(rect, QBrush(self.__dark)) sectionSize = 2 if (self.__orientation == Qt.Horizontal): numIntervals = rect.width()/sectionSize else: numIntervals = rect.height()/sectionSize section = QRect() for i in range(int(numIntervals)): if self.__orientation == Qt.Horizontal: section.setRect(rect.x() + i*sectionSize, rect.y(), sectionSize, rect.heigh()) else: section.setRect(rect.x(), rect.y() + i*sectionSize, rect.width(), sectionSize) ratio = float(i)/float(numIntervals) color = QColor() color.setHsv(h1 + int(ratio*(h2-h1) + 0.5), s1 + int(ratio*(s2-s1) + 0.5), v1 + int(ratio*(v2-v1) + 0.5)) painter.fillRect(section, color) painter.restore()
def drawColorBar(self, painter, rect): h1, s1, v1, _ = self.__light.getHsv() h2, s2, v2, _ = self.__dark.getHsv() painter.save() painter.setClipRect(rect) painter.setClipping(True) painter.fillRect(rect, QBrush(self.__dark)) sectionSize = 2 if self.__orientation == Qt.Horizontal: numIntervals = rect.width() / sectionSize else: numIntervals = rect.height() / sectionSize section = QRect() for i in range(int(numIntervals)): if self.__orientation == Qt.Horizontal: section.setRect(rect.x() + i * sectionSize, rect.y(), sectionSize, rect.heigh()) else: section.setRect(rect.x(), rect.y() + i * sectionSize, rect.width(), sectionSize) ratio = float(i) / float(numIntervals) color = QColor() color.setHsv( h1 + int(ratio * (h2 - h1) + 0.5), s1 + int(ratio * (s2 - s1) + 0.5), v1 + int(ratio * (v2 - v1) + 0.5) ) painter.fillRect(section, color) painter.restore()