def paintEvent(self, event):
        painter = qt.QPainter(self)

        style = qt.QApplication.style()

        area = self.__drawArea()
        pixmapRect = self.__pixMapRect()

        option = qt.QStyleOptionProgressBar()
        option.initFrom(self)
        option.rect = area
        option.state = ((self.isEnabled() and qt.QStyle.State_Enabled)
                        or qt.QStyle.State_None)
        style.drawControl(qt.QStyle.CE_ProgressBarGroove, option, painter,
                          self)

        painter.save()
        pen = painter.pen()
        pen.setWidth(1)
        pen.setColor(qt.Qt.black if self.isEnabled() else qt.Qt.gray)
        painter.setPen(pen)
        painter.drawRect(pixmapRect.adjusted(-1, -1, 1, 1))
        painter.restore()

        if self.isEnabled() and self.__pixmap is not None:
            painter.drawPixmap(
                area.adjusted(self._SLIDER_WIDTH / 2, self._PIXMAP_VOFFSET,
                              -self._SLIDER_WIDTH / 2 + 1,
                              -self._PIXMAP_VOFFSET + 1), self.__pixmap,
                self.__pixmap.rect())

        for name in ('first', 'second'):
            rect = self.__sliderRect(name)
            option = qt.QStyleOptionButton()
            option.initFrom(self)
            option.icon = self.__icons[name]
            option.iconSize = rect.size() * 0.7
            if option.state & qt.QStyle.State_MouseOver:
                option.state ^= qt.QStyle.State_MouseOver
            if self.__focus == name:
                option.state |= qt.QStyle.State_HasFocus
            elif option.state & qt.QStyle.State_HasFocus:
                option.state ^= qt.QStyle.State_HasFocus
            option.rect = rect
            style.drawControl(qt.QStyle.CE_PushButton, option, painter, self)
    def paintEvent(self, event):
        super(CalibrantPreview, self).paintEvent(event)
        painter = qt.QPainter(self)

        # border
        option = qt.QStyleOptionProgressBar()
        option.initFrom(self)
        option.rect = self.rect()
        option.state = qt.QStyle.State_Enabled if self.isEnabled(
        ) else qt.QStyle.State_None
        style = qt.QApplication.style()
        style.drawControl(qt.QStyle.CE_ProgressBarGroove, option, painter,
                          self)

        # content
        pixmapRect = self.rect().adjusted(self._PIXMAP_OFFSET,
                                          self._PIXMAP_OFFSET,
                                          -self._PIXMAP_OFFSET,
                                          -self._PIXMAP_OFFSET)
        pixmap = self.__getPixmap(size=pixmapRect.width())
        if pixmap is not None:
            painter.drawPixmap(pixmapRect, pixmap, pixmap.rect())
Exemple #3
0
    def paintEvent(self, event):
        painter = qt.QPainter(self)

        style = qt.QApplication.style()

        area = self.__drawArea()
        if self.__pixmap is not None:
            pixmapRect = self.__pixMapRect()

            option = qt.QStyleOptionProgressBar()
            option.initFrom(self)
            option.rect = area
            option.state = (qt.QStyle.State_Enabled
                            if self.isEnabled() else qt.QStyle.State_None)
            style.drawControl(qt.QStyle.CE_ProgressBarGroove, option, painter,
                              self)

            painter.save()
            pen = painter.pen()
            pen.setWidth(1)
            pen.setColor(qt.Qt.black if self.isEnabled() else qt.Qt.gray)
            painter.setPen(pen)
            painter.drawRect(pixmapRect.adjusted(-1, -1, 0, 1))
            painter.restore()

            if self.isEnabled():
                rect = area.adjusted(self._SLIDER_WIDTH // 2,
                                     self._PIXMAP_VOFFSET,
                                     -self._SLIDER_WIDTH // 2,
                                     -self._PIXMAP_VOFFSET + 1)
                painter.drawPixmap(rect, self.__pixmap, self.__pixmap.rect())
        else:
            option = StyleOptionRangeSlider()
            option.initFrom(self)
            option.rect = area
            option.sliderPosition1 = self.__firstValue
            option.sliderPosition2 = self.__secondValue
            option.handlerRect1 = self.__sliderRect("first")
            option.handlerRect2 = self.__sliderRect("second")
            option.minimum = self.__minValue
            option.maximum = self.__maxValue
            option.state = (qt.QStyle.State_Enabled
                            if self.isEnabled() else qt.QStyle.State_None)
            if self.__hoverControl == "groove":
                option.state |= qt.QStyle.State_MouseOver
            elif option.state & qt.QStyle.State_MouseOver:
                option.state ^= qt.QStyle.State_MouseOver
            self.drawRangeSliderBackground(painter, option, self)

        # Avoid glitch when moving handles
        hoverControl = self.__moving or self.__hoverControl

        for name in ('first', 'second'):
            rect = self.__sliderRect(name)
            option = qt.QStyleOptionButton()
            option.initFrom(self)
            option.icon = self.__icons[name]
            option.iconSize = rect.size() * 0.7
            if hoverControl == name:
                option.state |= qt.QStyle.State_MouseOver
            elif option.state & qt.QStyle.State_MouseOver:
                option.state ^= qt.QStyle.State_MouseOver
            if self.__focus == name:
                option.state |= qt.QStyle.State_HasFocus
            elif option.state & qt.QStyle.State_HasFocus:
                option.state ^= qt.QStyle.State_HasFocus
            option.rect = rect
            style.drawControl(qt.QStyle.CE_PushButton, option, painter, self)
Exemple #4
0
    def paint(cls, painter, option, index):
        progress = index.data(Qt.Qt.EditRole)

        progressBarOption = Qt.QStyleOptionProgressBar()
        progressBarOption.rect = option.rect
        progressBarOption.minimum = 0
        progressBarOption.maximum = 100
        progressBarOption.progress = progress
        progressBarOption.text = '{0}%'.format(progress)
        progressBarOption.textVisible = True

        Qt.QApplication.style().drawControl(Qt.QStyle.CE_ProgressBar,
                                            progressBarOption, painter)
        return True


#
#
# class DoubleEditor(NodeEditor):
#     persistent = False
#
#     def __init__(self, *args, **kwargs):
#         super(DoubleEditor, self).__init__(*args, **kwargs)
#         edit = Qt.QLineEdit()
#         edit.setValidator(Qt.QDoubleValidator())
#         edit.editingFinished.connect(self.valueChanged)
#         self.setWidget(edit)
#
#     def getEditorData(self):
#         return float(self.widget().text())
#
#     def updateFromNode(self, node):
#         # TODO : try/catch/log
#         edit = self.widget()
#         edit.setText(str(node.value(self.column)))
#         return True
#
#
# class QColorEditor(NodeEditor):
#     persistent = True
#
#     def __init__(self, *args, **kwargs):
#         super(QColorEditor, self).__init__(*args, **kwargs)
#         base = Qt.QWidget()
#         layout = Qt.QHBoxLayout(base)
#         layout.setContentsMargins(0, 0, 0, 0)
#         button = Qt.QToolButton()
#         icon = Qt.QIcon(Qt.QPixmap(32, 32))
#         button.setIcon(icon)
#         layout.addWidget(button)
#         self.setWidget(base)
#         button.clicked.connect(self.__showColorDialog)
#         layout.addStretch(1)
#
#         self.__color = None
#         self.__dialog = None
#         self.__previousColor = None
#
#     def getEditorData(self):
#         return self.__color
#
#     def updateFromNode(self, node):
#         if isinstance(node, QColorNode):
#             qColor = node.data(self.column, Qt.Qt.EditRole)
#             if qColor is not None:
#                 self._setColor(qColor)
#             else:
#                 # TODO : error
#                 pass
#             return True
#
#         return False
#
#     def _setColor(self, qColor):
#         widget = self.widget()
#         button = widget.findChild(Qt.QToolButton)
#         pixmap = Qt.QPixmap(32, 32)
#         pixmap.fill(qColor)
#         button.setIcon(Qt.QIcon(pixmap))
#         self.__currentColor = qColor
#
#     def __showColorDialog(self):
#         if self.__dialog is not None:
#             self.__dialog.reject()
#             return
#         self.__dialog = dialog = Qt.QColorDialog()
#         dialog.setOption(Qt.QColorDialog.ShowAlphaChannel, True)
#         self.__previousColor = self.__currentColor
#         dialog.setAttribute(Qt.Qt.WA_DeleteOnClose)
#         dialog.currentColorChanged.connect(self.__colorChanged)
#         dialog.finished.connect(self.__dialogClosed)
#         dialog.show()
#
#     def __colorChanged(self, color):
#         self.__color = color
#         self._setColor(color)
#         self.valueChanged(color)
#
#     def __dialogClosed(self, result):
#         if result == Qt.QDialog.Rejected:
#             self.__colorChanged(self.__previousColor)
#         self.__dialog = None
#         self.__previousColor = None
#
#
# class QColorNode(Node):
#     editors = QColorEditor
Exemple #5
0
    def paintEvent(self, event):
        painter = Qt.QPainter(self)

        style = Qt.QApplication.style()

        area = self.__drawArea()
        pixmapRect = self.__pixMapRect()

        sliders = self.__sliders

        option = Qt.QStyleOptionProgressBar()
        option.initFrom(self)
        option.rect = area
        option.state = ((self.isEnabled() and Qt.QStyle.State_Enabled)
                        or Qt.QStyle.State_None)
        style.drawControl(Qt.QStyle.CE_ProgressBarGroove, option, painter,
                          self)

        # showing interval rect only if show is forced or if there is not
        # background and show is True or None
        showRngBckgrnd = (self.__showRangeBackground
                          or (self.__pixmap and self.__showRangeBackground)
                          or (self.__pixmap is None
                              and self.__showRangeBackground is None)
                          or self.__showRangeBackground)

        alpha = (self.isEnabled() and 255) or 100

        if showRngBckgrnd:
            painter.save()
            rect = Qt.QRect(area)
            rect.setLeft(sliders['left'].center().x())
            rect.setRight(sliders['right'].center().x())
            gradient = Qt.QLinearGradient(area.topLeft(), area.bottomLeft())
            color = Qt.QColor(Qt.Qt.cyan)
            color.setAlpha(alpha)
            gradient.setColorAt(0., color)
            color = Qt.QColor(Qt.Qt.blue)
            color.setAlpha(alpha)
            gradient.setColorAt(1., color)
            brush = Qt.QBrush(gradient)
            painter.setBrush(brush)
            painter.drawRect(rect)
            painter.restore()

        if self.__pixmap and alpha == 255:
            painter.save()
            pen = painter.pen()
            pen.setWidth(2)
            pen.setColor(Qt.Qt.black)
            painter.setPen(pen)
            painter.drawRect(pixmapRect.adjusted(-1, -1, 1, 1))
            painter.restore()

            painter.drawPixmap(
                area.adjusted(self._sliderWidth / 2, self._pixmapVOffset,
                              -self._sliderWidth / 2, -self._pixmapVOffset),
                self.__pixmap, self.__pixmap.rect())

        option = Qt.QStyleOptionButton()
        option.initFrom(self)

        for side, slider in sliders.items():
            option.icon = self.__sliderIcons[side]
            option.iconSize = slider.size() * 0.7
            if self.__hover == side:
                option.state |= Qt.QStyle.State_MouseOver
            elif option.state & Qt.QStyle.State_MouseOver:
                option.state ^= Qt.QStyle.State_MouseOver
            if self.__focus == side:
                option.state |= Qt.QStyle.State_HasFocus
            elif option.state & Qt.QStyle.State_HasFocus:
                option.state ^= Qt.QStyle.State_HasFocus
            option.rect = slider
            style.drawControl(Qt.QStyle.CE_PushButton, option, painter, self)