Beispiel #1
0
    def paint(self, painter, option, index):
        painter.save()

        checked = index.model().data(index, Qt.UserRole)
        checkbox_indicator = QStyleOptionButton()

        #checkbox_indicator.state |= QStyle.State_Enabled

        if (index.flags() & Qt.ItemIsEditable) > 0:
            checkbox_indicator.state |= QStyle.State_Enabled
        else:
            checkbox_indicator.state |= QStyle.State_ReadOnly

        if checked:
            checkbox_indicator.state |= QStyle.State_On
        else:
            checkbox_indicator.state |= QStyle.State_Off

        checkbox_indicator.rect = QApplication.style().subElementRect(
            QStyle.SE_CheckBoxIndicator, checkbox_indicator, None)

        x = int(option.rect.center().x() - checkbox_indicator.rect.width() / 2)
        y = int(option.rect.center().y() -
                checkbox_indicator.rect.height() / 2)

        checkbox_indicator.rect.moveTo(x, y)

        if (option.state & QStyle.State_Selected):
            painter.fillRect(option.rect, option.palette.highlight())

        QApplication.style().drawControl(QStyle.CE_CheckBox,
                                         checkbox_indicator, painter)

        painter.restore()
    def paintSection(self, painter, rect, logicalIndex):
        painter.save()
        super(SelectableTableHeader, self).paintSection(painter, rect, logicalIndex)
        painter.restore()

        if logicalIndex in self._nonSelectableIndexes:
            return

        # check if boolean for this section exists
        if not self._isSectionSelected.has_key(logicalIndex):
            if self._selectionModel:
                if self.orientation() == Qt.Horizontal:
                    self._isSectionSelected[logicalIndex] = self._selectionModel.getColSelectionState(logicalIndex)
                elif self.orientation() == Qt.Vertical:
                    self._isSectionSelected[logicalIndex] = self._selectionModel.getRowSelectionState(logicalIndex)
            else:
                self._isSectionSelected[logicalIndex] = Qt.Checked

        option = QStyleOptionButton()
        option.rect = rect
        if self._isSectionSelected[logicalIndex] == Qt.Checked:
            option.state = QStyle.State_On | QStyle.State_Enabled
        elif self._isSectionSelected[logicalIndex] == Qt.Unchecked:
            option.state = QStyle.State_Off | QStyle.State_Enabled
        elif self._isSectionSelected[logicalIndex] == Qt.PartiallyChecked:
            option.state = QStyle.State_NoChange | QStyle.State_Enabled
        self.style().drawControl(QStyle.CE_CheckBox, option, painter)
 def paint( self, painter, option, index ):
     super(VoxelGridDelegate,self).paint(painter, option, index)
     column = GridManagerColumns.Columns[index.column()]
     # The only change we present here, is a "fake" button (It is a button, but just in appearance),
     # to invoke the Color Picker Widget, in the Color column.
     if( column == GridManagerColumns.Color ):
         button = QStyleOptionButton() # It looks like a button, but similarities ends here. It's just a skin.
         button.rect = self._get_color_picker_button_dimensions(option.rect)
         button.text = "...";
         # By the way, I couldn't change the color of the f***ing button. So i decided to use the background of the cell as the indicator
         button.state = QStyle.State_Enabled
         QApplication.style().drawControl( QStyle.CE_PushButton, button, painter )
Beispiel #4
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(1, 10, 10, 10)
            if self.isOn:
                option.state = QStyle.State_On
            else:
                option.state = QStyle.State_Off
            self.style().drawControl(QStyle.CE_CheckBox, option, painter)
Beispiel #5
0
    def paint(self, painter, option, index):
        '''
        Paint a checkbox without the label.
        '''

        value = index.model().data(index, Qt.DisplayRole)

        if value == None:
            return
        # we draw the background

        cg = QPalette.Disabled
        if option.state & QStyle.State_Enabled:
            cg = QPalette.Normal
            if not (option.state & QStyle.State_Active):
                cg = QPalette.Inactive

        r = QRect(option.rect.x(),option.rect.y(),option.rect.width(),option.rect.height())
        if option.state & QStyle.State_Selected:
            painter.fillRect(option.rect, option.palette.color(cg, QPalette.Highlight))
        elif index.data(Qt.BackgroundRole):
            # Alternating background color for the rows, to improve
            # readability
            # if index.row() % 2 == 1:
            #    painter.fillRect(option.rect, QColor(240,240,255))
            painter.fillRect(option.rect, index.data(Qt.BackgroundRole))
        else:
            painter.fillRect(option.rect, Qt.GlobalColor.white)

        checked = bool(index.model().data(index, Qt.DisplayRole))
        check_box_style_option = QStyleOptionButton()

        if (index.flags() & Qt.ItemIsEditable) > 0:
            check_box_style_option.state |= QStyle.State_Enabled
        else:
            check_box_style_option.state |= QStyle.State_ReadOnly

        if checked:
            check_box_style_option.state |= QStyle.State_On
        else:
            check_box_style_option.state |= QStyle.State_Off

        check_box_style_option.rect = self.getCheckBoxRect(option)

        # if not index.model().hasFlag(index, Qt.ItemIsEditable):
        if not ((index.flags() & Qt.ItemIsEditable) > 0):
             check_box_style_option.state |= QStyle.State_ReadOnly

        QApplication.style().drawControl(QStyle.CE_CheckBox, check_box_style_option, painter)
 def checkBoxRect(self, opt, editor):
     cb_option = QStyleOptionButton()
     style = QApplication.style()
     cb_rect = style.subElementRect(QStyle.SE_CheckBoxIndicator, cb_option,
                                    editor)
     cb_point = QPoint(
         opt.rect.x() + (opt.rect.width() - cb_rect.width()) / 2,
         opt.rect.y() + (opt.rect.height() - cb_rect.height()) / 2)
     return QRect(cb_point, cb_rect.size())
Beispiel #7
0
 def getCheckBoxRect(self, option):
     check_box_style_option = QStyleOptionButton()
     check_box_rect = QApplication.style().subElementRect(
         QStyle.SE_CheckBoxIndicator, check_box_style_option, None)
     check_box_point = 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)
     return QRect(check_box_point, check_box_rect.size())
Beispiel #8
0
    def paint(self, painter, option, index):
        checked = bool(index.data())
        check_box_style_option = QStyleOptionButton()

        if (index.flags() & Qt.ItemIsEditable) > 0:
            check_box_style_option.state |= QStyle.State_Enabled
        else:
            check_box_style_option.state |= QStyle.State_ReadOnly

        if checked:
            check_box_style_option.state |= QStyle.State_On
        else:
            check_box_style_option.state |= QStyle.State_Off

        check_box_style_option.rect = self.getCheckBoxRect(option)

        check_box_style_option.state |= QStyle.State_Enabled

        QApplication.style().drawControl(QStyle.CE_CheckBox,
                                         check_box_style_option, painter)
    def paintSection(self, painter, rect, logicalIndex):
        painter.save()
        super(SelectableTableHeader,
              self).paintSection(painter, rect, logicalIndex)
        painter.restore()

        if logicalIndex in self._nonSelectableIndexes:
            return

        # check if boolean for this section exists
        if not self._isSectionSelected.has_key(logicalIndex):
            if self._selectionModel:
                if self.orientation() == Qt.Horizontal:
                    self._isSectionSelected[
                        logicalIndex] = self._selectionModel.getColSelectionState(
                            logicalIndex)
                elif self.orientation() == Qt.Vertical:
                    self._isSectionSelected[
                        logicalIndex] = self._selectionModel.getRowSelectionState(
                            logicalIndex)
            else:
                self._isSectionSelected[logicalIndex] = Qt.Checked

        option = QStyleOptionButton()
        option.rect = rect
        if self._isSectionSelected[logicalIndex] == Qt.Checked:
            option.state = QStyle.State_On | QStyle.State_Enabled
        elif self._isSectionSelected[logicalIndex] == Qt.Unchecked:
            option.state = QStyle.State_Off | QStyle.State_Enabled
        elif self._isSectionSelected[logicalIndex] == Qt.PartiallyChecked:
            option.state = QStyle.State_NoChange | QStyle.State_Enabled
        self.style().drawControl(QStyle.CE_CheckBox, option, painter)
Beispiel #10
0
 def paintEvent(self, e):
     p = QPainter(self)
     style = QApplication.style()
     option = QStyleOptionButton()
     style.drawControl(QStyle.CE_PushButton, option, p)
     self._painted = True
Beispiel #11
0
    def paint(self, painter, option, index):
        """
        Re-implementation of the paint method. 
        This will render a stream item that contains an icon, the name, 
        a description, the game being played, and a dropdown menu.
        """
        super(StreamItemDelegate, self).paint(painter, option, index)
        stream = index.data()

        if option.state & QStyle.State_MouseOver:
            painter.fillRect(option.rect, option.palette.color(QPalette.Highlight))
            painter.setPen(Qt.white)
        else:
            painter.setPen(Qt.black)

        # I'll have a rectangle pls.
        r = option.rect

        # Draw the Service icon (Twitch, etc)
        icon = get_service_icon(stream.service)
        icon_size = 16
        icon_offset = (r.height()/2) - (icon_size/2)
        if stream.status == 0: #offline
            icon.paint(painter, r.left()+10, r.top()+icon_offset, icon_size, icon_size, Qt.AlignLeft | Qt.AlignVCenter, mode=QIcon.Disabled) 
        else:
            icon.paint(painter, r.left()+10, r.top()+icon_offset, icon_size, icon_size, Qt.AlignLeft | Qt.AlignVCenter, mode=QIcon.Normal) 

        # Paint the stream name
        painter.drawText(r.left()+40, r.top()-8, r.width(), r.height(), Qt.AlignVCenter | Qt.AlignLeft, stream.name)

        # Paint the game name, if any.
        painter.save()
        name_len = painter.fontMetrics().width(stream.name)
        font = painter.font()
        font.setPixelSize(9)
        font.setItalic(True)
        painter.setFont(font)
        painter.setPen(QColor(*get_game_colour(stream.game)))
        # Position of the left edge + the length of the name text + the offset of the stream name + an additional offset for padding.
        painter.drawText((r.left()+name_len)+40, r.top()-8, r.width(), r.height(), Qt.AlignVCenter | Qt.AlignLeft, stream.game)
        painter.restore()

        # Paint a dropdown button for options.
        x1 = 50; y1 = 8; iw = 9; ih = 6; 
        orect = r.adjusted(name_len+x1, y1, -(r.width()-(name_len+x1+iw)), -(r.height()-(y1+ih))) # Rectangle to store the dropdown icon
        hrect = orect.adjusted(-4, -3, 6, 5) # Rectangle to hover within.
        hbg = orect.adjusted(-2, -1, 2, 1) # Rectangle to draw the rounded background in
        options_button = QStyleOptionButton()
        # Cursor must be translated to relative positioning via the parent widget, note that is this is not a widget.
        if hrect.contains(self.parent.mapFromGlobal(QCursor.pos())):
            # Hover event for the dropdown options button
            options_button.icon = self.icons["down_hover"]
            # Draw a background behind the icon
            painter.save()
            painter.setRenderHints(painter.Antialiasing | painter.HighQualityAntialiasing)
            painter.setPen(QPen(QColor(101, 99, 98)))
            painter.setBrush(QBrush(QColor(101, 99, 98)))
            painter.drawRoundRect(QRectF(hbg), 10.0, 5.0)
            painter.restore()
        else:
            options_button.icon = self.icons["down_default"]
        options_button.iconSize = QSize(iw, ih)
        options_button.rect = orect
        options_button.features = QStyleOptionButton.Flat
        # Paint a Push Button Control.
        QApplication.style().drawControl(QStyle.CE_PushButton, options_button, painter)
         
        # Paint the description/status?
        painter.save()
        if stream.status == 0: #offline
            painter.setPen(Qt.darkGray)
            painter.drawText(r.left()+40, r.top()+8, r.width(), r.height(), Qt.AlignVCenter | Qt.AlignLeft, "Offline")
        else:
            painter.setPen(Qt.darkGreen)
            painter.drawText(r.left()+40, r.top()+8, r.width(), r.height(), Qt.AlignVCenter | Qt.AlignLeft, stream.channel.status)
        painter.restore()