예제 #1
0
    def paint(self, painter, option, index):

        if index.column() == 0:
            painter.save()
            icon = QtGui.QIcon()
            icon.addPixmap(
                QtGui.QPixmap(":/spotify/resources/icons/play_lgrey.png"),
                QtGui.QIcon.Normal, QtGui.QIcon.Off)
            palette = QApplication.palette()
            opt = QStyleOptionButton()
            opt.icon = icon
            opt.iconSize = QtCore.QSize(30, 30)
            opt.rect = option.rect

            color = palette.highlight().color() \
                if option.state & QStyle.State_Selected \
                else QtGui.QColor(index.model().data(index, Qt.BackgroundColorRole))

            if self._pressed and self._pressed == (index.row(),
                                                   index.column()):
                opt.state = QStyle.State_Enabled | QStyle.State_Sunken
                opt.icon = icon

            elif self._hover and self._hover == (index.row(), index.column()):
                print('oh man')
                opt.icon = icon
            else:
                opt.state = QStyle.State_Enabled | QStyle.State_Raised
            QApplication.style().drawControl(QStyle.CE_PushButtonLabel, opt,
                                             painter)
            painter.restore()
        else:
            QStyledItemDelegate.paint(self, painter, option, index)
예제 #2
0
 def paint(self, painter, option, index):
     """Paint a checkbox without the label."""
     if (option.state & QStyle.State_Selected):
         painter.fillRect(option.rect, option.palette.highlight())
     checked = True
     if index.data() == False:
         checked = False
     elif index.data() == True:
         checked = True
     else:
         checked = None
     checkbox_style_option = QStyleOptionButton()
     if (index.flags() & Qt.ItemIsEditable) > 0:
         checkbox_style_option.state |= QStyle.State_Enabled
     else:
         checkbox_style_option.state |= QStyle.State_ReadOnly
     if checked == True:
         checkbox_style_option.state |= QStyle.State_On
     elif checked == False:
         checkbox_style_option.state |= QStyle.State_Off
     elif checked is None:
         checkbox_style_option.state |= QStyle.State_NoChange
     checkbox_style_option.rect = self.get_checkbox_rect(option)
     # noinspection PyArgumentList
     QApplication.style().drawControl(QStyle.CE_CheckBox,
                                      checkbox_style_option, painter)
예제 #3
0
    def paint(self, painter, option, index):

        # Check data
        source_index = self.proxy_model.mapToSource(index)
        row = source_index.row()
        column = source_index.column()
        checked = self.proxy_model.sourceModel().dataset[row][column]

        # Build rect to draw
        style_option = QStyleOptionButton()
        check_box_rect = QApplication.style().subElementRect(
            QStyle.SE_CheckBoxIndicator, style_option, None)
        check_box_pos = QPoint(
            option.rect.x() + option.rect.width() / 2 -
            check_box_rect.width() / 2,
            option.rect.y() + option.rect.height() / 2 -
            check_box_rect.height() / 2,
        )
        rect_to_draw = QRect(check_box_pos, check_box_rect.size())

        # Build check box
        opts = QStyleOptionButton()
        opts.state |= QStyle.State_Active | QStyle.State_Enabled
        opts.state |= QStyle.State_On if checked else QStyle.State_Off
        opts.rect = rect_to_draw
        QApplication.style().drawControl(QStyle.CE_CheckBox, opts, painter)
 def paint(self, painter, option, index):
     painter.save()
     opt = QStyleOptionButton()
     opt.text = str(index.data())
     opt.rect = option.rect
     opt.palette = option.palette
     opt.state = QStyle.State_Enabled | QStyle.State_Raised
     QApplication.style().drawControl(QStyle.CE_PushButton, opt, painter)
     painter.restore()
예제 #5
0
 def paint(self, painter, option, index):
     """Paint a checkbox without the label."""
     if option.state & QStyle.State_Selected:
         painter.fillRect(option.rect, option.palette.highlight())
     checkbox_style_option = QStyleOptionButton()
     checkbox_style_option.rect = self.get_checkbox_rect(option)
     if (index.flags() & Qt.ItemIsEditable) > 0:
         checkbox_style_option.state |= QStyle.State_Enabled
     else:
         checkbox_style_option.state |= QStyle.State_ReadOnly
     self._do_paint(painter, checkbox_style_option, index)
 def paint(self, painter, option, index):
     painter.save()
     opt = QStyleOptionButton()
     opt.text = str(index.data())
     opt.rect = option.rect
     opt.palette = option.palette
     task = self.__taskStorage.getTaskByNum(index.row())
     if task.state != "RUN":
         opt.state = QStyle.State_Enabled | QStyle.State_Raised
     else:
         opt.state = QStyle.State_Enabled | QStyle.State_Sunken
     QApplication.style().drawControl(QStyle.CE_PushButton, opt, painter)
     painter.restore()
예제 #7
0
    def paintSection(self, painter, rect, logicalIndex):
        painter.save()
        QHeaderView.paintSection(self, painter, rect, logicalIndex)
        painter.restore()

        if logicalIndex == 0:
            option = QStyleOptionButton()
            option.rect = QRect(3, 7, 10, 10)
            if self.isOn:
                option.state = QStyle.State_On
            else:
                option.state = QStyle.State_Off
            self.style().drawControl(QStyle.CE_CheckBox, option, painter)
예제 #8
0
    def paint(self, painter: QtGui.QPainter, option: QStyleOptionViewItem,
              index: QModelIndex) -> None:
        checked: bool = index.data(Qt.DisplayRole)

        options = QStyleOptionButton()
        if (index.flags() & Qt.ItemIsEditable) > 0:
            options.state |= QStyle.State_Enabled
        else:
            options.state |= QStyle.State_ReadOnly
        if checked:
            options.state |= QStyle.State_On
        else:
            options.state |= QStyle.State_Off

        options.rect = self.__getCheckboxRect(option)
        if not (index.flags() & Qt.ItemIsEditable):
            options.state |= QStyle.State_ReadOnly
        QApplication.style().drawControl(QStyle.CE_CheckBox, options, painter)
예제 #9
0
    def paintSection(self, painter: QPainter, rect: QRect,
                     logicalIndex: int) -> None:
        painter.save()
        super().paintSection(painter, rect, logicalIndex)
        painter.restore()
        if self.__checkboxSection == logicalIndex:
            # Compute checkbox position
            checkboxSize: int = 15
            width: int = self.sectionSize(logicalIndex)
            height: int = self.height()
            cbStartWidth: int = max(0, (width - checkboxSize) // 2)
            cbStartHeight: int = max(0, (height - checkboxSize) // 2)

            option = QStyleOptionButton()
            option.rect = QRect(cbStartWidth, cbStartHeight, 15, 15)
            if self.__isChecked:
                option.state |= QStyle.State_On
            else:
                option.state |= QStyle.State_Off
            QApplication.style().drawPrimitive(QStyle.PE_IndicatorCheckBox,
                                               option, painter)