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)
def paint(self, painter, option, index): """ Paint the items in the table. If the item referred to by <index> is a StarRating, we handle the painting ourselves. For the other items, we let the base class handle the painting as usual. In a polished application, we'd use a better check than the column number to find out if we needed to paint the stars, but it works for the purposes of this example. """ if index.column() == 3: starRating = StarRating(index.data()) # If the row is currently selected, we need to make sure we # paint the background accordingly. if option.state & QStyle.State_Selected: # The original C++ example used option.palette.foreground() to # get the brush for painting, but there are a couple of # problems with that: # - foreground() is obsolete now, use windowText() instead # - more importantly, windowText() just returns a brush # containing a flat color, where sometimes the style # would have a nice subtle gradient or something. # Here we just use the brush of the painter object that's # passed in to us, which keeps the row highlighting nice # and consistent. painter.fillRect(option.rect, painter.brush()) # Now that we've painted the background, call starRating.paint() # to paint the stars. starRating.paint(painter, option.rect, option.palette) else: 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 = QStyleOptionProgressBar() 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)
def paint(self, painter, option, index): if option.state & QStyle.State_Selected: item_color = index.data(role=Qt.TextColorRole) if item_color is None: item_color = Qt.black option.palette.setColor(QPalette.HighlightedText, item_color) color = self.combineColors(self.color_default, self.background(option, index)) option.palette.setColor(QPalette.Highlight, color) QStyledItemDelegate.paint(self, painter, option, index)
def paint(self, painter, option, index): """ paint event handler @param painter: @type painter: @param option: @type option: @param index: @type index: """ rect = QRectF(option.rect) layer = self.parent().img.layersStack[-1 - index.row()] # mask and merged layer flag (for exposure fusion and HDR merge) if index.column() == 2: if self.parent().img is not None: if layer.maskIsSelected: text = index.data() + ' *' else: text = index.data() + ' ' if layer.mergingFlag: text = text + ' +' if layer.maskIsEnabled: painter.save() painter.setPen(Qt.red) painter.drawText(rect, text, QTextOption(Qt.AlignCenter)) painter.restore() return painter.drawText(rect, text, QTextOption(Qt.AlignCenter)) # visibility elif index.column() == 0: painter.save() bgColor = option.palette.color(QPalette.Window) bgColor = bgColor.red(), bgColor.green(), bgColor.blue() dark = (max(bgColor) <= 128) if option.state & QStyle.State_Selected: c = option.palette.color(QPalette.Highlight) painter.fillRect(rect, c) if self.parent().img.layersStack[-1 - index.row()].visible: px = self.inv_px1 if dark or ( option.state & QStyle.State_Selected) else self.px1 else: px = self.inv_px2 if dark or ( option.state & QStyle.State_Selected) else self.px2 painter.drawPixmap(rect, px, QRectF(0, 0, px.width(), px.height())) painter.restore() else: # call default QStyledItemDelegate.paint(self, painter, option, index)
def paint(self, painter: QStylePainter, option: QStyleOptionViewItem, index: QModelIndex) -> None: """ Paint a checkbox without the label. :param painter: This draws the widget. :type painter: QStylePainter :param option: Option for the style of checkbox. :type option: QStyleOptionViewItem :param index: Index for the painted checkbox. :type index: QModelIndex :return: None :rtype: NoneType """ QStyledItemDelegate.paint(self, painter, option, index) if index.column() == 1 and isinstance( index.internalPointer(), Property) and index.internalPointer().getType() == bool: checked = index.internalPointer().getValue() check_box_style_option = QtWidgets.QStyleOptionButton() if (index.flags() & QtCore.Qt.ItemIsEditable) > 0: check_box_style_option.state |= QtWidgets.QStyle.State_Enabled else: check_box_style_option.state |= QtWidgets.QStyle.State_ReadOnly if checked: check_box_style_option.state |= QtWidgets.QStyle.State_On else: check_box_style_option.state |= QtWidgets.QStyle.State_Off check_box_style_option.rect = self.getCheckBoxRect(option) check_box_style_option.state |= QtWidgets.QStyle.State_Enabled QtWidgets.QApplication.style().drawControl( QtWidgets.QStyle.CE_CheckBox, check_box_style_option, painter)
def paint(self, painter, option, index): """ Paint the items in the table. If the item referred to by <index> is a StarRating, we handle the painting ourselves. For the other items, we let the base class handle the painting as usual. In a polished application, we'd use a better check than the column number to find out if we needed to paint the stars, but it works for the purposes of this example. """ if option.state & QStyle.State_Enabled: if option.state & QStyle.State_Active: color_group = QPalette.Normal else: color_group = QPalette.Inactive else: color_group = QPalette.Disabled if option.state & QStyle.State_Selected: painter.fillRect( option.rect, option.palette.color(color_group, QPalette.Highlight)) imagen = QPixmap() try: imagen.loadFromData(index.data()) # , Qt.DisplayRole except TypeError: return QStyledItemDelegate.paint(self, painter, option, index) imagen = imagen.scaled(QSize(16, 16), Qt.KeepAspectRatio) width = imagen.width() height = imagen.height() """Para calcular el lugar donde se tiene que dibujar 1. option.rect te da: (0, 0, width() , height() ) of the image 2. Del punto en el que hay que empezar a dibujar, le sumamos la mitad del ancho de la celda 3. Y luego le restamos el ancho del objeto para que quede en la mitad """ x = option.rect.x() + (option.rect.width() / 2) - (width / 2) y = option.rect.y() + (option.rect.height() / 2) - (height / 2) # x,y cordenadas - 32,32 ancho y alto de la imagen - la imagen painter.drawPixmap(x, y, imagen) pen = painter.pen() painter.setPen(option.palette.color(QPalette.Mid))
def paint(self, painter, option, index): if self._is_relationship_index(index): super().paint(painter, option, index) else: QStyledItemDelegate.paint(self, painter, option, index)
def paint(self, painter, option, index): if self._is_scenario_alternative_index(index): super().paint(painter, option, index) else: QStyledItemDelegate.paint(self, painter, option, index)
def paint(self, painter, option, index): if index.column() == NUT_PERCENT_COL: progress_bar_option = QStyleOptionProgressBar() progress_bar_option.rect = option.rect progress_bar_option.minimum = 0 progress_bar_option.maximum = 100 progress_bar_option.textVisible = True progress = index.data(role=Qt.DisplayRole) p = QPalette() if progress is None: # A bug in the progress bar for the fusion style causes a thin vertical strip # of the progress bar chunk to be painted to the left of a progress bar with # less than 1% progess while drawn in a table view. # This strip is normally covered by the table's grid lines, but I have them disabled. # My workaround to display a completely empty progress bar without the strip # is to fill the progress bar and simply turn the color to white progress_bar_option.progress = 100 progress_bar_option.text = "No data" p.setColor(QPalette.Highlight, QColor(Qt.white)) p.setColor(QPalette.HighlightedText, Qt.darkGray) progress_bar_option.palette = p elif progress == -1: progress_bar_option.progress = 100 progress_bar_option.text = "None set" p.setColor(QPalette.Highlight, QColor(Qt.white)) p.setColor(QPalette.HighlightedText, Qt.darkGray) progress_bar_option.palette = p elif round(progress) == 0: progress_bar_option.progress = 100 progress_bar_option.text = "0%" p.setColor(QPalette.Highlight, QColor(Qt.white)) p.setColor(QPalette.HighlightedText, QColor(Qt.black)) progress_bar_option.palette = p elif 0 < round(progress) < 100: rounded_string = '{number:.{digits}f}%'.format(number=progress, digits=0) progress_bar_option.progress = round(progress) progress_bar_option.text = rounded_string elif 100 <= round(progress): rounded_string = '{number:.{digits}f}%'.format(number=progress, digits=0) progress_bar_option.progress = 100 progress_bar_option.text = rounded_string #p.setColor(QPalette.Highlight, QColor(247, 202, 202)) #progress_bar_option.palette = p #QApplication.style().drawControl(QStyle.CE_ProgressBar, progress_bar_option, painter) QStyleFactory.create('fusion').drawControl(QStyle.CE_ProgressBar, progress_bar_option, painter) else: QStyledItemDelegate.paint(self, painter, option, index)