def paint(self, painter, option, index): new_percentage = int(index.data(Qt.UserRole)) pbar = QStyleOptionProgressBar() pbar.rect = option.rect pbar.minimum = 0 pbar.maximum = 100 default_color = QColor(0, 140, 255) if new_percentage < 0: new_percentage = 0 pbar_color = Qt.lightGray ptext = f"Ready to download" elif 0 <= new_percentage < 100: pbar_color = default_color ptext = f"Downloading ({new_percentage}%) .." elif new_percentage == 100: pbar_color = QColor(10, 180, 40) ptext = f"Download finished" else: new_percentage = 100 pbar_color = Qt.red ptext = f"Download failed" pbar.progress = new_percentage pbar.text = ptext pbar.textVisible = True palette = pbar.palette palette.setColor(QPalette.Highlight, pbar_color) pbar.palette = palette QApplication.style().drawControl(QStyle.CE_ProgressBar, pbar, painter)
def paint(self, painter, option, index): if index.column() != 1: QStyledItemDelegate.paint(self, painter, option, index) return model: Any[PlanetSearchResultsModel | QAbstractItemModel] = \ index.model() node = model.get_node(index) if node.node_type() in [NodeT.LOADING, NodeT.LOAD_MORE]: QStyledItemDelegate.paint(self, painter, option, index) return rect = option.rect painter.save() btn = QStyleOptionButton() btn.icon = COG_ICON btn.iconSize = QSize(18, 18) btn.features = QStyleOptionButton.Flat # btn.features |= QStyleOptionButton.HasMenu if option.state & QStyle.State_Selected: painter.fillRect(option.rect, option.palette.highlight()) btn.state = QStyle.State_Enabled btn.rect = QRect(rect.left() + rect.width() - 26, rect.top(), 26, rect.height()) QApplication.style().drawControl( QStyle.CE_PushButton, btn, painter) painter.restore()
def paint(self, painter, option, index): status, progress = index.data(PROGRESS_ROLE) status_name = status.name new_percentage = progress.percentage pbar = QStyleOptionProgressBar() pbar.rect = option.rect pbar.minimum = 0 pbar.maximum = 100 default_color = QColor(0, 140, 255) if status_name == "created" or status_name == "starting": pbar_color = default_color ptext = "Starting up simulation .." elif status_name == "initialized" or status_name == "postprocessing": pbar_color = default_color ptext = f"{new_percentage}%" elif status_name == "finished": pbar_color = QColor(10, 180, 40) ptext = f"{new_percentage}%" elif status_name == "ended": pbar_color = Qt.gray ptext = f"{new_percentage}% (stopped)" elif status_name == "crashed": pbar_color = Qt.red ptext = f"{new_percentage}% (crashed)" else: pbar_color = Qt.lightGray ptext = f"{status_name}" pbar.progress = new_percentage pbar.text = ptext pbar.textVisible = True palette = pbar.palette palette.setColor(QPalette.Highlight, pbar_color) pbar.palette = palette QApplication.style().drawControl(QStyle.CE_ProgressBar, pbar, painter)
def paint(self, painter, option, index): if index.column() != 0: QStyledItemDelegate.paint(self, painter, option, index) return model: Any[PlanetSearchResultsModel | QAbstractItemModel] = \ index.model() node: PlanetNode = model.get_node(index) # TODO: Style these, too? # if node.node_type() in [NodeT.LOADING, NodeT.LOAD_MORE]: # QStyledItemDelegate.paint(self, painter, option, index) # return option_vi = QStyleOptionViewItem(option) self.initStyleOption(option_vi, index) # noinspection PyUnusedLocal style = QApplication.style() \ if option_vi.widget is None else option_vi.widget.style() # style = self.parent().style() opt_rect = option_vi.rect doc = QTextDocument() doc.setHtml(option_vi.text) #print(option_vi.text) option_vi.text = '' style.drawControl(QStyle.CE_ItemViewItem, option_vi, painter) ctx = QAbstractTextDocumentLayout.PaintContext() # Highlighting text if item is selected # if option_vi.state & QStyle.State_Selected: # ctx.palette.setColor( # QPalette.Text, # option_vi.palette.color( # QPalette.Active, QPalette.HighlightedText)) text_rect = style.subElementRect(QStyle.SE_ItemViewItemText, option_vi) painter.save() painter.translate(text_rect.topLeft()) painter.setClipRect(text_rect.translated(-text_rect.topLeft())) doc.documentLayout().draw(painter, ctx) painter.restore() if option.state & QStyle.State_MouseOver: if node.has_footprint() or node.has_group_footprint(): painter.save() painter.setPen( QPen(QBrush(QColor.fromRgb(0, 157, 165, 245)), 1.5)) painter.setBrush(Qt.NoBrush) painter.drawRect(opt_rect.marginsRemoved(QMargins(1, 1, 1, 1))) painter.restore() if node.has_footprint() or node.has_group_footprint(): # noinspection PyUnresolvedReferences self.previewFootprint.emit(node) else: # noinspection PyUnresolvedReferences self.clearFootprint.emit() if not node.can_be_downloaded(): # Note: Needs to come last, so it covers checkbox control # TODO: Figure out way of having checkbox not drawn, but still # set Node's unchecked state # opt_btn = QStyleOptionButton() # opt_btn.operator = option ci_rect: QRect = style.subElementRect( QStyle.SE_ViewItemCheckIndicator, option_vi) # opt_btn.rect = ci_rect # but_opt = QStyleOptionButton(option) # opt_btn.state = QStyle.State_Off # style.drawControl(QStyle.CE_CheckBox, opt_btn, painter) painter.save() painter.setPen(Qt.NoPen) painter.setBrush(QBrush(QColor.fromRgb(250, 250, 250, 255))) painter.drawRoundedRect(ci_rect, ci_rect.height() / 6, ci_rect.height() / 6) LOCK_ICON.paint(painter, ci_rect, Qt.AlignCenter, QIcon.Normal) painter.restore()
def paint(self, painter, option, index): # print str(index.row()) + " / " + str(len(self.items)) # text = self.items[index.row()] text = self._items[1] option.text = text QApplication.style().drawControl(QStyle.CE_ItemViewItem, option, painter)