Exemplo n.º 1
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)
Exemplo n.º 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)
Exemplo n.º 3
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)
Exemplo n.º 4
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)
Exemplo n.º 5
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)
 def __init__(self, taskStorage, idPropertyName, gui=None, parent=None):
     super(DeleteButtonDelegate, self).__init__(parent)
     self._pressed = None
     self.__taskStorage = taskStorage
     self.__idPropertyName = idPropertyName
     self.__btn = QStyleOptionButton()
     self.__gui = gui
Exemplo n.º 7
0
 def paintEvent(self, e):
     p = QPainter(self)
     style = QApplication.style()
     option = QStyleOptionButton()
     style.drawControl(QStyle.CE_PushButton, option, p)
     self._painted = True
     QTimer.singleShot(0, self._emitPainted)
Exemplo n.º 8
0
 def __getCheckboxRect(option: QStyleOptionViewItem) -> QRect:
     check_options = QStyleOptionButton()
     check_rect = QApplication.style().subElementRect(
         QStyle.SE_CheckBoxIndicator, check_options, None)
     check_point = QPoint(
         option.rect.x() + option.rect.width() / 2 - check_rect.width() / 2,
         option.rect.y() + option.rect.height() / 2 -
         check_rect.height() / 2)
     return QRect(check_point, check_rect.size())
Exemplo n.º 9
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)
Exemplo n.º 10
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)
Exemplo n.º 11
0
 def get_checkbox_rect(self, option):
     checkbox_style_option = QStyleOptionButton()
     checkbox_rect = QApplication.style().subElementRect(QStyle.SE_CheckBoxIndicator, checkbox_style_option, None)
     if self._centered:
         checkbox_anchor = QPoint(
             option.rect.x() + option.rect.width() / 2 - checkbox_rect.width() / 2,
             option.rect.y() + option.rect.height() / 2 - checkbox_rect.height() / 2,
         )
     else:
         checkbox_anchor = QPoint(
             option.rect.x() + checkbox_rect.width() / 2, option.rect.y() + checkbox_rect.height() / 2
         )
     return QRect(checkbox_anchor, checkbox_rect.size())
Exemplo n.º 12
0
 def paintEvent(self, e):
     """ Draws the render setup button """
     painter = QPainter(self)
     option = QStyleOptionButton()
     option.initFrom(self)
     if self.isDown():
         option.state = QStyle.State_Sunken
     else:
         option.state = QStyle.State_Raised
      
     if self.enter:
         option.state = option.state | QStyle.State_MouseOver
      
     option.icon = self.icon()
     self.drawControl(QStyle.CE_PushButton, option, painter, self)
Exemplo n.º 13
0
 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()
Exemplo n.º 14
0
 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()
Exemplo n.º 15
0
    def __init__(self, parent: Optional[QWidget]):
        super().__init__(parent)
        self.ui = Ui_PathBrowseWidget()
        self.ui.setupUi(self)

        # Set the button to the minimum size for the
        font_metrics = self.fontMetrics()
        size = font_metrics.size(Qt.TextShowMnemonic, self.ui.browseButton.text())
        option = QStyleOptionButton()
        # If we do this, we get a larger minimum size. Why? TODO
        # self.ui.browseButton.initStyleOption(option)
        min_size = self.style().sizeFromContents(QStyle.CT_PushButton, option, size, self)
        self.ui.browseButton.setFixedWidth(min_size.width())

        self.ui.browseButton.clicked.connect(self.browse)