コード例 #1
0
    def paint(self, painter, option, index):
        # if item selected, override default theme
        # Keeps verdict color for cells and use a bold font
        if option.state & QStyle.State_Selected:
            option.state &= ~QStyle.State_Selected
            option.font.setBold(True)

        QStyledItemDelegate.paint(self, painter, option, index)

        item = index.model().get_item(index)
        if item and item.downloading:
            # Draw progress bar
            progressBarOption = QStyleOptionProgressBarV2()
            progressBarHeight = option.rect.height() / 4
            progressBarOption.rect = QRect(
                option.rect.x(),
                option.rect.y() + (option.rect.height() - progressBarHeight),
                option.rect.width(),
                progressBarHeight,
            )
            progressBarOption.minimum = 0
            progressBarOption.maximum = 100
            progressBarOption.textAlignment = Qt.AlignCenter

            progressBarOption.progress = item.progress

            QApplication.style().drawControl(QStyle.CE_ProgressBar, progressBarOption, painter)
コード例 #2
0
    def paint(self, painter, option, index):
        # noinspection PyArgumentList
        style = QApplication.instance().style()

        if index.data(CheckableItemDelegate.CheckTypeRole):
            # Size and spacing in current style
            is_radio = index.data(CheckableItemDelegate.CheckTypeRole) == CheckableItemDelegate.RadioCheckType
            if is_radio:
                button_width = style.pixelMetric(QStyle.PM_ExclusiveIndicatorWidth, option)
                spacing = style.pixelMetric(QStyle.PM_RadioButtonLabelSpacing, option)
            else:
                button_width = style.pixelMetric(QStyle.PM_IndicatorWidth, option)
                spacing = style.pixelMetric(QStyle.PM_CheckBoxLabelSpacing, option)

            # Draw default appearance shifted to right
            myOption = option
            left = myOption.rect.left()
            myOption.rect.setLeft(left + spacing + button_width)
            QStyledItemDelegate.paint(self, painter, myOption, index)

            # Draw check button to open space (where expand indicator would be)
            myOption.rect.setLeft(left)
            myOption.rect.setWidth(button_width)

            if index.data(CheckableItemDelegate.CheckedRole):
                myOption.state |= QStyle.State_On
            else:
                myOption.state |= QStyle.State_Off

            if is_radio:
                style.drawPrimitive(QStyle.PE_IndicatorRadioButton, myOption, painter)
            else:
                style.drawPrimitive(QStyle.PE_IndicatorCheckBox, myOption, painter)
        else:
            QStyledItemDelegate.paint(self, painter, option, index)
コード例 #3
0
    def paint(self, painter, option, index):
        painter.save()
        palette = QApplication.palette()
        if index.isValid():
            color = palette.highlight().color() \
                if option.state & QStyle.State_Selected \
                else  QColor(Qt.white)
            painter.fillRect(option.rect, color)
            if (option.state and QStyle.State_Active):
                textColor = QPalette.HighlightedText if option.state & QStyle.State_Selected else QPalette.WindowText
            else:
                textColor = QPalette.WindowText
            
            col = index.column()
            val = index.model().data(index).toFloat()[0]
            if col == 1:
                text = '%.2f %%  ' % (val*100)
            else:
                text = '%d  ' % (val)
            
            QApplication.style().drawItemText(painter, option.rect, Qt.AlignRight | Qt.AlignVCenter,
                                              option.palette, True, text,
                                              textColor)
        else:
            QStyledItemDelegate.paint(painter, option, index)

        painter.restore()
コード例 #4
0
    def paint(self, painter, option, index):
        if option.state & QStyle.State_Selected:
            modelIndex = index.row()
            if modelIndex != self.currentIndex:
                model = index.model()
                self.currentIndex = modelIndex
                model.wantsUpdate()

        layer = index.data().toPyObject()
        if isinstance(layer, Layer):
            pic = QPixmap(option.rect.width(), option.rect.height())
            w = self._w
            w.layer = layer
            w.setGeometry(option.rect)
            w.setPalette(option.palette)

            # Manually set alternating background colors for the rows
            if index.row() % 2 == 0:
                itemBackgroundColor = self.parent().palette().color(
                    QPalette.Base)
            else:
                itemBackgroundColor = self.parent().palette().color(
                    QPalette.AlternateBase)
            pallete = w.palette()
            pallete.setColor(QPalette.Window, itemBackgroundColor)
            w.setPalette(pallete)
            w.render(pic)
            painter.drawPixmap(option.rect, pic)
        else:
            QStyledItemDelegate.paint(self, painter, option, index)
コード例 #5
0
 def paint(self, painter, option, index):
     " Hides the dotted outline "
     itemOption = QStyleOptionViewItem(option)
     if itemOption.state & QStyle.State_HasFocus != 0:
         itemOption.state = itemOption.state & ~QStyle.State_HasFocus
     QStyledItemDelegate.paint(self, painter, itemOption, index)
     return
コード例 #6
0
ファイル: layerwidget.py プロジェクト: lfiaschi/volumina
    def paint(self, painter, option, index):
        if option.state & QStyle.State_Selected:
            modelIndex = index.row()
            if modelIndex != self.currentIndex:
                model = index.model()
                self.currentIndex = modelIndex
                model.wantsUpdate()

        layer = index.data().toPyObject()
        if isinstance(layer, Layer):
            pic = QPixmap( option.rect.width(), option.rect.height() )
            w = self._w
            w.layer = layer
            w.setGeometry( option.rect )
            w.setPalette( option.palette )
            
            # Manually set alternating background colors for the rows
            if index.row() % 2 == 0:
                itemBackgroundColor = self.parent().palette().color(QPalette.Base)
            else:
                itemBackgroundColor = self.parent().palette().color(QPalette.AlternateBase)
            pallete = w.palette()
            pallete.setColor( QPalette.Window, itemBackgroundColor )
            w.setPalette(pallete)
            w.render(pic)            
            painter.drawPixmap( option.rect, pic )
        else:
            QStyledItemDelegate.paint(self, painter, option, index)
コード例 #7
0
    def paint(self, painter, option, index):
        painter.save()
        palette = QApplication.palette()
        if index.isValid():
            color = palette.highlight().color() \
                if option.state & QStyle.State_Selected \
                else  QColor(Qt.white)
            painter.fillRect(option.rect, color)
            if (option.state and QStyle.State_Active):
                textColor = QPalette.HighlightedText if option.state & QStyle.State_Selected else QPalette.WindowText
            else:
                textColor = QPalette.WindowText

            col = index.column()
            val = index.model().data(index).toFloat()[0]
            if col == 1:
                text = '%.2f %%  ' % (val * 100)
            else:
                text = '%d  ' % (val)

            QApplication.style().drawItemText(painter, option.rect,
                                              Qt.AlignRight | Qt.AlignVCenter,
                                              option.palette, True, text,
                                              textColor)
        else:
            QStyledItemDelegate.paint(painter, option, index)

        painter.restore()
コード例 #8
0
ファイル: itemdelegates.py プロジェクト: eaglexmw/codimension
 def paint( self, painter, option, index ):
     " Hides the dotted outline "
     itemOption = QStyleOptionViewItem( option )
     if itemOption.state & QStyle.State_HasFocus != 0:
         itemOption.state = itemOption.state & ~QStyle.State_HasFocus
     QStyledItemDelegate.paint( self, painter, itemOption, index )
     return
コード例 #9
0
 def paint(self, painter, option, index):
     # pylint: disable=missing-docstring
     painter.save()
     painter.setPen(QColor(212, 212, 212))
     painter.drawLine(option.rect.bottomLeft(), option.rect.bottomRight())
     painter.restore()
     QStyledItemDelegate.paint(self, painter, option, index)
    def paint(self, painter, option, index):
        # if item selected, override default theme
        # Keeps verdict color for cells and use a bold font
        if option.state & QStyle.State_Selected:
            option.state &= ~ QStyle.State_Selected
            option.font.setBold(True)

        QStyledItemDelegate.paint(self, painter, option, index)

        item = index.model().get_item(index)
        if item and item.downloading:
            # Draw progress bar
            progressBarOption = QStyleOptionProgressBarV2()
            progressBarHeight = option.rect.height() / 4
            progressBarOption.rect = QRect(
                option.rect.x(),
                option.rect.y() +
                (option.rect.height() - progressBarHeight),
                option.rect.width(),
                progressBarHeight)
            progressBarOption.minimum = 0
            progressBarOption.maximum = 100
            progressBarOption.textAlignment = Qt.AlignCenter

            progressBarOption.progress = item.progress

            QApplication.style().drawControl(
                QStyle.CE_ProgressBar,
                progressBarOption,
                painter)
コード例 #11
0
ファイル: OWPythonScript.py プロジェクト: AutumnLight/orange
    def paint(self, painter, option, index):
        script = index.data(Qt.DisplayRole).toPyObject()

        if script.flags & Script.Modified:
            option = QStyleOptionViewItemV4(option)
            option.palette.setColor(QPalette.Text, QColor(Qt.red))
            option.palette.setColor(QPalette.Highlight, QColor(Qt.darkRed))
        QStyledItemDelegate.paint(self, painter, option, index)
コード例 #12
0
ファイル: OWPythonScript.py プロジェクト: yisuax11/orange2
    def paint(self, painter, option, index):
        script = index.data(Qt.DisplayRole).toPyObject()

        if script.flags & Script.Modified:
            option = QStyleOptionViewItemV4(option)
            option.palette.setColor(QPalette.Text, QColor(Qt.red))
            option.palette.setColor(QPalette.Highlight, QColor(Qt.darkRed))
        QStyledItemDelegate.paint(self, painter, option, index)
コード例 #13
0
ファイル: dialogfee.py プロジェクト: doyinspc/schoolmgtapp
 def paint(self, painter, option, index):
     if not index.parent().isValid():
         QStyledItemDelegate.paint(self, painter, option, index)
     else:
         widget = option.widget
         style = widget.style() if widget else QApplication.style()
         opt = QStyleOptionButton()
         opt.rect = option.rect
         opt.text = index.data()
         opt.state |= QStyle.State_On if index.data(Qt.CheckStateRole) else QStyle.State_Off
         style.drawControl(QStyle.CE_CheckBox, opt, painter, widget)
コード例 #14
0
 def paint(self, painter, option, index):
     """paint right aligned checkbox"""
     viewItemOption = QStyleOptionViewItemV4(option)
     if self.cellFilter(index):
         textMargin = self.__textMargin()
         newRect = QStyle.alignedRect(
             option.direction, Qt.AlignRight,
             QSize(option.decorationSize.width() + 5,
                   option.decorationSize.height()),
             QRect(option.rect.x() + textMargin, option.rect.y(),
                   option.rect.width() - (2 * textMargin),
                   option.rect.height()))
         viewItemOption.rect = newRect
     QStyledItemDelegate.paint(self, painter, viewItemOption, index)
コード例 #15
0
 def paint(self, painter, option, index):
     QStyledItemDelegate.paint(self, painter, option, index)
     borders = index.data(BorderRole)
     if borders:
         color = index.data(BorderColorRole) or self.color
         painter.save()
         painter.setPen(color)
         r = option.rect
         for side, p1, p2 in (("t", r.topLeft(), r.topRight()),
                              ("r", r.topRight(), r.bottomRight()),
                              ("b", r.bottomLeft(), r.bottomRight()),
                              ("l", r.topLeft(), r.bottomLeft())):
             if side in borders:
                 painter.drawLine(p1, p2)
         painter.restore()
コード例 #16
0
ファイル: owconfusionmatrix.py プロジェクト: rbax/orange3
 def paint(self, painter, option, index):
     QStyledItemDelegate.paint(self, painter, option, index)
     borders = index.data(BorderRole)
     if borders:
         color = index.data(BorderColorRole) or self.color
         painter.save()
         painter.setPen(color)
         r = option.rect
         for side, p1, p2 in (("t", r.topLeft(), r.topRight()),
                              ("r", r.topRight(), r.bottomRight()),
                              ("b", r.bottomLeft(), r.bottomRight()),
                              ("l", r.topLeft(), r.bottomLeft())):
             if side in borders:
                 painter.drawLine(p1, p2)
         painter.restore()
コード例 #17
0
ファイル: central_panel.py プロジェクト: Nicogue/Encuentro
    def paint(self, painter, option, index):
        """Render the delegate for the item."""
        if index.column() != self._html_column:
            return QStyledItemDelegate.paint(self, painter, option, index)

        options = QStyleOptionViewItemV4(option)
        self.initStyleOption(options, index)

        if options.widget is None:
            style = QApplication.style()
        else:
            style = options.widget.style()

        doc = QTextDocument()
        doc.setHtml(options.text)

        options.text = ""
        style.drawControl(QStyle.CE_ItemViewItem, options, painter)

        ctx = QAbstractTextDocumentLayout.PaintContext()

        textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
        painter.save()
        painter.translate(textRect.topLeft())
        painter.setClipRect(textRect.translated(-textRect.topLeft()))
        doc.documentLayout().draw(painter, ctx)
        painter.restore()
コード例 #18
0
ファイル: central_panel.py プロジェクト: Nicogue/Encuentro
    def paint(self, painter, option, index):
        """Render the delegate for the item."""
        if index.column() != self._html_column:
            return QStyledItemDelegate.paint(self, painter, option, index)

        options = QStyleOptionViewItemV4(option)
        self.initStyleOption(options, index)

        if options.widget is None:
            style = QApplication.style()
        else:
            style = options.widget.style()

        doc = QTextDocument()
        doc.setHtml(options.text)

        options.text = ""
        style.drawControl(QStyle.CE_ItemViewItem, options, painter)

        ctx = QAbstractTextDocumentLayout.PaintContext()

        textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
        painter.save()
        painter.translate(textRect.topLeft())
        painter.setClipRect(textRect.translated(-textRect.topLeft()))
        doc.documentLayout().draw(painter, ctx)
        painter.restore()
コード例 #19
0
 def paint(self, painter, option, index):
     self.initStyleOption(option, index)
     # No idea why, but this cast is required if we want to have access to the V4 valuess
     option = QStyleOptionViewItemV4(option)
     if (index.column() == 1) and (option.state & QStyle.State_Selected):
         cboption = QStyleOptionComboBox()
         cboption.rect = option.rect
         # On OS X (with Qt4.6.0), adding State_Enabled to the flags causes the whole drawing to
         # fail (draw nothing), but it's an OS X only glitch. On Windows, it works alright.
         cboption.state |= QStyle.State_Enabled
         QApplication.style().drawComplexControl(QStyle.CC_ComboBox, cboption, painter)
         painter.setBrush(option.palette.text())
         rect = QRect(option.rect)
         rect.setLeft(rect.left()+4)
         painter.drawText(rect, Qt.AlignLeft, option.text)
     else:
         QStyledItemDelegate.paint(self, painter, option, index)
コード例 #20
0
 def paint(self, painter, option, index):
     self.initStyleOption(option, index)
     # No idea why, but this cast is required if we want to have access to the V4 valuess
     option = QStyleOptionViewItemV4(option)
     if (index.column() == 1) and (option.state & QStyle.State_Selected):
         cboption = QStyleOptionComboBox()
         cboption.rect = option.rect
         # On OS X (with Qt4.6.0), adding State_Enabled to the flags causes the whole drawing to
         # fail (draw nothing), but it's an OS X only glitch. On Windows, it works alright.
         cboption.state |= QStyle.State_Enabled
         QApplication.style().drawComplexControl(QStyle.CC_ComboBox,
                                                 cboption, painter)
         painter.setBrush(option.palette.text())
         rect = QRect(option.rect)
         rect.setLeft(rect.left() + 4)
         painter.drawText(rect, Qt.AlignLeft, option.text)
     else:
         QStyledItemDelegate.paint(self, painter, option, index)
コード例 #21
0
ファイル: item_delegate.py プロジェクト: glasmasin/moneyguru
    def paint(self, painter, option, index):
        """Performs custom painting of value of data in the model and decorations.

         Performs custom painting of value of data in the model at the specified index
         plus any decorations used in that column.

         Args:
            painter - QPainter
            option - QStyleOptionViewItemV4
            index - QModelIndex
        """
        self.initStyleOption(option, index)
        # I don't know why I have to do this. option.version returns 4, but still, when I try to
        # access option.features, boom-crash. The workaround is to force a V4.
        option = QStyleOptionViewItemV4(option)
        decorations = self._get_decorations(index, bool(option.state & QStyle.State_Selected))
        if decorations:
            option.decorationPosition = QStyleOptionViewItemV4.Right
            decorationWidth = sum(dec.pixmap.width() for dec in decorations)
            decorationHeight = max(dec.pixmap.height() for dec in decorations)
            option.decorationSize = QSize(decorationWidth, decorationHeight)
            option.features |= QStyleOptionViewItemV4.HasDecoration
        self._prepare_paint_options(option, index)

        xOffset = 0
        # First added for #15, the painting of custom amount information.  This can
        # be used as a pattern for painting any column of information.
        value_painter = self._get_value_painter(index)
        self._display_text = value_painter is None
        QStyledItemDelegate.paint(self, painter, option, index)
        if value_painter is not None:
            value_option = QStyleOptionViewItemV4(option)
            rect = value_option.rect
            rect = QRect(rect.left(), rect.top(), rect.width() - xOffset, rect.height())
            value_option.rect = rect
            value_painter.paint(painter, value_option, index)

        for dec in decorations:
            pixmap = dec.pixmap
            x = option.rect.right() - pixmap.width() - xOffset
            y = option.rect.center().y() - (pixmap.height() // 2)
            rect = QRect(x, y, pixmap.width(), pixmap.height())
            painter.drawPixmap(rect, pixmap)
            xOffset += pixmap.width()
コード例 #22
0
    def paint(self, Painter, Option, Index):
        #if Index.column() == 0:
            #print("Painting", Option.decorationSize, Index)
            #branchRect = QRect(0,Option.rect.top(), Option.rect.left(), Option.rect.height()*2)
            #branchRect = QRect(Option.rect.topLeft(), QPoint(Option.rect.bottomRight().x(), Option.rect.bottomRight().y()))
            #Painter.setCompositionMode(QPainter.CompositionMode_Multiply)
            #Painter.fillRect(branchRect, QColor("blue"))
            #Painter.setCompositionMode(QPainter.CompositionMode_SourceOver)

        return QStyledItemDelegate.paint(self, Painter, Option, Index)
コード例 #23
0
ファイル: layerwidget.py プロジェクト: buotex/volumina
    def paint(self, painter, option, index):
        if option.state & QStyle.State_Selected:
            modelIndex = index.row()
            if modelIndex != self.currentIndex:
                model = index.model()
                self.currentIndex = modelIndex
                model.wantsUpdate()

        layer = index.data().toPyObject()
        if isinstance(layer, Layer):
            pic = QPixmap( option.rect.width(), option.rect.height() )
            w = self._w
            w.layer = layer
            w.setGeometry( option.rect )
            w.setPalette( option.palette )
            w.render(pic)            
            painter.drawPixmap( option.rect, pic )
        else:
            QStyledItemDelegate.paint(self, painter, option, index)
コード例 #24
0
    def paint(self, painter, option, index):
        #noinspection PyArgumentList
        style = QApplication.instance().style()

        if index.data(CheckableItemDelegate.CheckTypeRole):
            # Size and spacing in current style
            is_radio = index.data(CheckableItemDelegate.CheckTypeRole) == \
                CheckableItemDelegate.RadioCheckType
            if is_radio:
                button_width = style.pixelMetric(
                    QStyle.PM_ExclusiveIndicatorWidth, option)
                spacing = style.pixelMetric(QStyle.PM_RadioButtonLabelSpacing,
                                            option)
            else:
                button_width = style.pixelMetric(QStyle.PM_IndicatorWidth,
                                                 option)
                spacing = style.pixelMetric(QStyle.PM_CheckBoxLabelSpacing,
                                            option)

            # Draw default appearance shifted to right
            myOption = option
            left = myOption.rect.left()
            myOption.rect.setLeft(left + spacing + button_width)
            QStyledItemDelegate.paint(self, painter, myOption, index)

            # Draw check button to open space (where expand indicator would be)
            myOption.rect.setLeft(left)
            myOption.rect.setWidth(button_width)

            if index.data(CheckableItemDelegate.CheckedRole):
                myOption.state |= QStyle.State_On
            else:
                myOption.state |= QStyle.State_Off

            if is_radio:
                style.drawPrimitive(QStyle.PE_IndicatorRadioButton, myOption,
                                    painter)
            else:
                style.drawPrimitive(QStyle.PE_IndicatorCheckBox, myOption,
                                    painter)
        else:
            QStyledItemDelegate.paint(self, painter, option, index)
コード例 #25
0
ファイル: layerwidget.py プロジェクト: kemaleren/volumina
 def paint(self, painter, option, index):
     if option.state & QStyle.State_Selected:
         modelIndex = index.row()
         if modelIndex != self.currentIndex:
             model = index.model()
             self.currentIndex = modelIndex
             model.wantsUpdate()
     
     layer = index.data().toPyObject()
     if isinstance(layer, Layer):
         self._layerPainter.layer = layer
         isSelected = option.state & QStyle.State_Selected
         if isSelected:
             painter.fillRect(option.rect, QColor(0,255,0,10))
         if self.expandAll or option.state & QStyle.State_Selected:
             self._layerPainter.paint(painter, option.rect, option.palette, 'Expanded', isSelected)
         else:
             self._layerPainter.paint(painter, option.rect, option.palette, 'ReadOnly', False)
     else:
         QStyledItemDelegate.paint(self, painter, option, index)
コード例 #26
0
 def paint(self, painter, option, index):
     if index.column() == DESCRIPTION:
         text = index.model().data(index).toString()
         palette = QApplication.palette()
         document = QTextDocument()
         document.setDefaultFont(option.font)
         if option.state & QStyle.State_Selected:
             document.setHtml(
                 QString("<font color=%1>%2</font>").arg(
                     palette.highlightedText().color().name()).arg(text))
         else:
             document.setHtml(text)
         color = (palette.highlight().color() if option.state
                  & QStyle.State_Selected else QColor(index.model().data(
                      index, Qt.BackgroundColorRole)))
         painter.save()
         painter.fillRect(option.rect, color)
         painter.translate(option.rect.x(), option.rect.y())
         document.drawContents(painter)
         painter.restore()
     else:
         QStyledItemDelegate.paint(self, painter, option, index)
コード例 #27
0
ファイル: gsbui.py プロジェクト: toyg/plasmaapplets
    def paint(self, painter, option, index):
        self.initStyleOption( option, index) # required 
        overdueColour = QColor(
                            self.options.readEntry("overdue_colour","#ff6666"))
        grace_period = int(self.options.readEntry("grace","5").toString())
        if index.isValid():
            
            # -- begin overriding color depending on date
            model = index.model()
            colDate = model.position_for_header('date')
            colExpDate = model.position_for_header('expected_date')
            
            model = index.model()
            column = index.column()
            today = datetime.today()
            
            dateExpIndex = model.index(index.row(),colExpDate)
            dateQv = model.data(dateExpIndex,Qt.DisplayRole)
                
            if dateQv.toString() == "":
                dateIndex = model.index(index.row(),colDate)
                dateQv = model.data(dateIndex,Qt.DisplayRole)                    

            if type(dateQv) == type(QVariant()):
                date = dateQv.toDateTime().toPyDateTime()
            elif type(dateQv) == type(QDateTime()):
                date = dateQv.toPyDateTime()
                        
            if (today - date).days > grace_period:
                
                
                painter.save()
                painter.fillRect(option.rect, overdueColour)
                painter.translate(option.rect.x(), option.rect.y())
                painter.restore()
            # -- end overriding color depending on date
            
            
        QStyledItemDelegate.paint(self,painter,option,index)
コード例 #28
0
 def paint(self, painter, option, index):
     self.initStyleOption(option, index)
     # I don't know why I have to do this. option.version returns 4, but still, when I try to
     # access option.features, boom-crash. The workaround is to force a V4.
     option = QStyleOptionViewItemV4(option)
     decorations = self._get_decorations(index, bool(option.state & QStyle.State_Selected))
     if decorations:
         option.decorationPosition = QStyleOptionViewItemV4.Right
         decorationWidth = sum(dec.pixmap.width() for dec in decorations)
         decorationHeight = max(dec.pixmap.height() for dec in decorations)
         option.decorationSize = QSize(decorationWidth, decorationHeight)
         option.features |= QStyleOptionViewItemV4.HasDecoration
     self._prepare_paint_options(option, index)
     QStyledItemDelegate.paint(self, painter, option, index)
     xOffset = 0
     for dec in decorations:
         pixmap = dec.pixmap
         x = option.rect.right() - pixmap.width() - xOffset
         y = option.rect.center().y() - (pixmap.height() // 2)
         rect = QRect(x, y, pixmap.width(), pixmap.height())
         painter.drawPixmap(rect, pixmap)
         xOffset += pixmap.width()
コード例 #29
0
ファイル: ships_ans.py プロジェクト: DaoQiu/VimProject
 def paint(self, painter, option, index):
     if index.column() == DESCRIPTION:
         text = index.model().data(index).toString()
         palette = QApplication.palette()
         document = QTextDocument()
         document.setDefaultFont(option.font)
         if option.state & QStyle.State_Selected:
             document.setHtml(QString("<font color=%1>%2</font>") 
                     .arg(palette.highlightedText().color().name())
                     .arg(text))
         else:
             document.setHtml(text)
         color = (palette.highlight().color()
                  if option.state & QStyle.State_Selected
                  else QColor(index.model().data(index,
                              Qt.BackgroundColorRole)))
         painter.save()
         painter.fillRect(option.rect, color)
         painter.translate(option.rect.x(), option.rect.y())
         document.drawContents(painter)
         painter.restore()
     else:
         QStyledItemDelegate.paint(self, painter, option, index)
コード例 #30
0
    def paint(self, painter, option, index):
        painter.save()
        if index.isValid():

            style = self.parent().style()
            styleOption = QStyleOptionViewItemV4(option)

            node = index.internalPointer()
            val = index.model().data(index).toPyObject()

            if node.typeInfo == 'CODE':
                if node.valueFormat == 'percent':
                    text = '%.2f %%  ' % (val * 100)
                elif node.valueFormat == 'integer':
                    text = '%d  ' % val
                else:
                    text = '%.2f  ' % val

                styleOption.text = text
                styleOption.displayAlignment = Qt.AlignRight

                style.drawControl(QStyle.CE_ItemViewItem, styleOption, painter)

            elif node.typeInfo == 'BAREME' and index.column() == 2:
                styleOption = QStyleOptionButton()
                styleOption.rect = option.rect
                styleOption.text = QString('Editer')
                styleOption.textVisible = True
                styleOption.state = styleOption.state | QStyle.State_Enabled
                style.drawControl(QStyle.CE_PushButton, styleOption, painter)
            else:
                QStyledItemDelegate.paint(self, painter, styleOption, index)

        else:
            QStyledItemDelegate.paint(painter, option, index)

        painter.restore()
コード例 #31
0
    def paint(self, painter, option, index):
        painter.save()
        if index.isValid():

            style = self.parent().style()
            styleOption = QStyleOptionViewItemV4(option)

            node = index.internalPointer()
            val = index.model().data(index).toPyObject()

            if node.typeInfo == 'CODE':
                if node.valueFormat == 'percent':
                    text = '%.2f %%  ' % (val*100)
                elif node.valueFormat == 'integer':
                    text = '%d  ' % val
                else:
                    text = '%.2f  ' % val

                styleOption.text = text
                styleOption.displayAlignment = Qt.AlignRight

                style.drawControl(QStyle.CE_ItemViewItem, styleOption, painter)
                
            elif node.typeInfo == 'BAREME' and index.column()==2:
                styleOption = QStyleOptionButton()
                styleOption.rect = option.rect
                styleOption.text = QString('Editer')
                styleOption.textVisible = True
                styleOption.state = styleOption.state | QStyle.State_Enabled
                style.drawControl(QStyle.CE_PushButton, styleOption, painter)
            else:
                QStyledItemDelegate.paint(self, painter, styleOption, index)
            
        else:
            QStyledItemDelegate.paint(painter, option, index)

        painter.restore()
コード例 #32
0
ファイル: scoring.py プロジェクト: ospalh/kajongg-fork
 def paint(self, painter, option, index):
     """where the real work is done..."""
     item = index.internalPointer()
     if isinstance(item, ScorePlayerItem) and item.parent.row() == 3 and index.column() != 0:
         for idx, playerItem in enumerate(index.parent().internalPointer().children):
             chart = index.model().chart(option.rect, index, playerItem)
             if chart:
                 painter.save()
                 painter.translate(option.rect.topLeft())
                 painter.setPen(self.colors[idx])
                 painter.setRenderHint(QPainter.Antialiasing)
                 # if we want to use a pen width > 1, we can no longer directly drawPolyline
                 # separately per cell beause the lines spread vertically over two rows: We would
                 # have to draw the lines into one big pixmap and copy from the into the cells
                 painter.drawPolyline(*chart) # pylint: disable=W0142
                 painter.restore()
         return
     return QStyledItemDelegate.paint(self, painter, option, index)
コード例 #33
0
 def paint(self, painter, option, index):
     delegate = self.delegates.get(index.column())
     if delegate is not None:
         delegate.paint(painter, option, index)
     else:
         QStyledItemDelegate.paint(self, painter, option, index)
コード例 #34
0
    def paint (self, painter, option, index):
        '''
        @param painter QPainter
        @param option    QStyleOptionViewItem
        @param index   QModelIndex
        '''

        itemRect = option.rect

        textW = self.columnWidths[index.column()]

        if index.column() is StockMatchTableModel.COL_TICKER:

            painter.save()

            m = index.model()
            line1 = m.data(index, Qt.DisplayRole).toString()
            line1 = option.fontMetrics.elidedText(line1, Qt.ElideLeft, textW)           

            # Paint the background first and then set the pen color
            if option.state & QStyle.State_Selected:
                painter.fillRect(itemRect, Qt.white)
                self.setPenColor(painter, Qt.darkBlue)
            else:
                linearGradient = self.createLinearGradient(itemRect, Qt.black, Qt.blue)
                painter.fillRect(itemRect, linearGradient)
                self.setPenColor(painter, Qt.white)

            textRect = itemRect
            painter.drawText(textRect, Qt.AlignVCenter | Qt.AlignCenter, line1)

            painter.restore()

        elif index.column() is StockMatchTableModel.COL_NAME:
           # Name column
            
            painter.save()

            m = index.model()
            line1 = m.data(index, Qt.DisplayRole).toString()
            line1 = option.fontMetrics.elidedText(line1, Qt.ElideRight, textW)
            line2 = m.data(index, StockMatchTableModel.ROLE_SUBTEXT1).toString()

            # Paint the background first and then set the pen color
            if option.state & QStyle.State_Selected:
                linearGradient = self.createLinearGradient(itemRect, Qt.white, Qt.yellow)
                painter.fillRect(itemRect, linearGradient)
                self.setPenColor(painter, Qt.darkBlue)
            else:
                linearGradient = self.createLinearGradient(itemRect, Qt.blue, Qt.darkBlue)
                painter.fillRect(itemRect, linearGradient)
                self.setPenColor(painter, Qt.white)

            lineSp = option.fontMetrics.lineSpacing()
            numLines = 2

            leftMargin = self.MARGIN
            textRect = QRect(itemRect.left() + leftMargin, itemRect.top() + self.MARGIN,
                             itemRect.width(), numLines * lineSp)
            painter.drawText(textRect, Qt.AlignTop | Qt.AlignLeft, line1)

            textRect.adjust(0, option.fontMetrics.lineSpacing(), 0, 0)

            # Draw the subtext
            subTextColor = painter.pen().color()
            subTextColor.setAlphaF(0.5)
            painter.setPen(subTextColor)
            painter.drawText(textRect, Qt.AlignTop | Qt.AlignLeft, line2)


            painter.restore()
        else:
            QStyledItemDelegate.paint(self, painter, option, index)
コード例 #35
0
 def paint(self, painter, option, index):
     model = index.model()
     row, col = index.row(), index.column()
     QStyledItemDelegate.paint(self, painter, option, index)
コード例 #36
0
 def paint(self, painter, option, index):
     painter.save()
     painter.setPen(QColor(212, 212, 212))
     painter.drawLine(option.rect.bottomLeft(), option.rect.bottomRight())
     painter.restore()
     QStyledItemDelegate.paint(self, painter, option, index)
コード例 #37
0
ファイル: paint.py プロジェクト: SuperSaiyanSSS/DatabaseHIT
 def paint(self, painter, option, index):
     myoption = QStyleOptionViewItem(option)
     myoption.displayAlignment |= (Qt.AlignRight | Qt.AlignVCenter)
     QStyledItemDelegate.paint(self, painter, myoption, index)
コード例 #38
0
ファイル: machsnap.py プロジェクト: ChannelFinder/hla
 def paint(self, painter, option, index):
     model = index.model()
     row, col = index.row(), index.column()
     QStyledItemDelegate.paint(self, painter, option, index)
コード例 #39
0
ファイル: genericdelegates.py プロジェクト: DaoQiu/VimProject
 def paint(self, painter, option, index):
     delegate = self.delegates.get(index.column())
     if delegate is not None:
         delegate.paint(painter, option, index)
     else:
         QStyledItemDelegate.paint(self, painter, option, index)
コード例 #40
0
 def paint(self, painter, option, index):
     QStyledItemDelegate.paint(self, painter, option, index)
コード例 #41
0
ファイル: owcolor.py プロジェクト: Coding4Sec/orange3
 def paint(self, painter, option, index):
     painter.save()
     painter.setPen(QColor(212, 212, 212))
     painter.drawLine(option.rect.bottomLeft(), option.rect.bottomRight())
     painter.restore()
     QStyledItemDelegate.paint(self, painter, option, index)