def asExecPin(pin, painter, option, widget): lod = pin.owningNode().canvasRef().getLodValueFromCurrentScale(3) frame = QtCore.QRectF(QtCore.QPointF(0, 0), pin.geometry().size()) w = frame.width() / 2 h = frame.height() / 2 halfPinSize = pin.pinSize / 2 painter.setFont(pin._font) painter.setPen(PinPainter._execPen) if lod < 3 and not pin.bLabelHidden: textWidth = QtGui.QFontMetrics(painter.font()).width(pin.displayName()) textHeight = QtGui.QFontMetrics(painter.font()).height() x = 1 + pin.pinSize + halfPinSize if pin.direction == PinDirection.Output: x = frame.width() - textWidth - pin.pinSize - 1 yCenter = textHeight - textHeight / 3 painter.setPen(QtGui.QPen(pin.labelColor, 0.5, QtCore.Qt.SolidLine)) painter.drawText(x, yCenter, pin.displayName()) if pin._rawPin.hasConnections(): painter.setBrush(QtGui.QBrush(pin.color())) else: painter.setBrush(QtCore.Qt.NoBrush) pinCenter = pin.pinCenter() xOffset = pinCenter.x() - pin.pinSize if pin.direction == PinDirection.Input else pinCenter.x() - pin.pinSize * 0.8 arrow = QtGui.QPolygonF([QtCore.QPointF(2, 0.0), QtCore.QPointF(2 + pin.pinSize / 2.0, 0.0), QtCore.QPointF(2 + pin.pinSize, pin.pinSize / 2.0), QtCore.QPointF(2 + pin.pinSize / 2.0, pin.pinSize), QtCore.QPointF(2, pin.pinSize)]).translated(xOffset, 1) painter.drawPolygon(arrow.translated(0, halfPinSize / 2)) if pin.hovered: painter.setPen(QtCore.Qt.NoPen) painter.setBrush(QtGui.QColor(128, 128, 128, 30)) painter.drawRoundedRect(frame, 3, 3)
def paint(self, painter, option, widget): frame = QtCore.QRectF(QtCore.QPointF(0, 0), self.geometry().size()) frame = frame.translated(self.pinSize * 1.1, 0) groupBGColor = self.owningNode().color.lighter(150) bgRect = QtCore.QRectF(frame) bgRect.setX(0) painter.setFont(self._font) painter.setPen(QtGui.QPen(self.labelColor, 1.0)) painter.drawText(frame, self.name) painter.setPen(QtGui.QPen(self.labelColor, 0.1)) square = QtCore.QRectF( QtCore.QPointF(0, 0), QtCore.QSizeF(self.pinSize / 1.1, self.pinSize / 1.1)) square2 = square.translated(0, (self.pinSize / 1.1) / 3) painter.drawRect(square2) font = QtGui.QFont(self._font) font.setPixelSize(7) painter.setFont(font) if not self.expanded: x = QtGui.QFontMetrics(font).width("+") square = square.translated(x / 3, 0.5) painter.drawText(square, "+") else: x = QtGui.QFontMetrics(font).width("-") square = square.translated(x / 3, 0.5) painter.drawText(square, "-")
def asArrayPin(pin, painter, option, widget): lod = pin.owningNode().canvasRef().getCanvasLodValueFromCurrentScale() SWITCH_LOD = editableStyleSheet().PinSwitch[0] gridSize = 3 cellW = pin.pinSize / gridSize cellH = pin.pinSize / gridSize pinCenter = pin.pinCenter() halfPinSize = pin.pinSize / 2 painter.setBrush(QtGui.QBrush(pin.color())) painter.setPen(QtGui.QPen(QtCore.Qt.black, 0.2)) for row in range(gridSize): for column in range(gridSize): x = row * cellW + pinCenter.x() - halfPinSize y = column * cellH + pinCenter.y() - halfPinSize painter.drawRect(x, y, cellW, cellH) if lod < SWITCH_LOD and not pin.bLabelHidden: frame = QtCore.QRectF(QtCore.QPointF(0, 0), pin.geometry().size()) halfPinSize = pin.pinSize / 2 painter.setFont(pin._font) textWidth = QtGui.QFontMetrics(painter.font()).width( pin.displayName()) textHeight = QtGui.QFontMetrics(painter.font()).height() x = 1 + pin.pinSize + halfPinSize if pin.direction == PinDirection.Output: x = frame.width() - textWidth - pin.pinSize - 1 yCenter = textHeight - textHeight / 3 painter.setPen(PinPainter._valuePinNamePen) painter.drawText(x, yCenter, pin.name) if pin.hovered: painter.setPen(QtCore.Qt.NoPen) painter.setBrush(QtGui.QColor(128, 128, 128, 30)) painter.drawRoundedRect(frame, 3, 3)
def asListPin(pin, painter, option, widget): lod = pin.owningNode().canvasRef().getLodValueFromCurrentScale(3) cellW = pin.pinSize cellH = pin.pinSize / 3 pinCenter = pin.pinCenter() halfPinSize = pin.pinSize / 2 painter.setBrush(QtGui.QBrush(pin.color())) painter.setPen(QtGui.QPen(QtCore.Qt.black, 0.2)) for row in range(3): x = pinCenter.x() - halfPinSize y = row * cellH + halfPinSize + pin.pinCircleDrawOffset.y() painter.drawRect(x, y, cellW, cellH) if lod < 3: frame = QtCore.QRectF(QtCore.QPointF(0, 0), pin.geometry().size()) halfPinSize = pin.pinSize / 2 painter.setFont(pin._font) textWidth = QtGui.QFontMetrics(painter.font()).width(pin.displayName()) textHeight = QtGui.QFontMetrics(painter.font()).height() x = 1 + pin.pinSize + halfPinSize if pin.direction == PinDirection.Output: x = frame.width() - textWidth - pin.pinSize - 1 yCenter = textHeight - textHeight / 3 painter.setPen(PinPainter._valuePinNamePen) painter.drawText(x, yCenter, pin.name) if pin.hovered: painter.setPen(QtCore.Qt.NoPen) painter.setBrush(QtGui.QColor(128, 128, 128, 30)) painter.drawRoundedRect(frame, 3, 3)
def sizeHint(self, which, constraint): height = QtGui.QFontMetrics(self._font).height() width = self.pinSize * 2 if not self.bLabelHidden: width += QtGui.QFontMetrics(self._font).width(self.displayName()) if not self.isVisible(): width = 0 height = 0 return QtCore.QSizeF(width, height)
def _paint_status(self, painter, option, status_item): _rect = option.rect _status_handle = zfused_api.status.Status(status_item.id()) painter.setPen(QtGui.QPen(QtGui.QColor(0, 0, 0, 0), 0)) #painter.setBrush(QtGui.QColor(_status_handle.data()["Color"])) painter.setBrush( QtGui.QColor(constants.Constants.STATUS_BACKGROUND_COLOR)) painter.drawRoundedRect(option.rect, 1, 1) fm = QtGui.QFontMetrics(painter.font()) painter.setPen( QtGui.QPen(QtGui.QColor(_status_handle.data()["Color"]), 1)) _status_text = u"{} · {}".format(_status_handle.full_name_code(), status_item.child_count()) _status_rect = QtCore.QRectF(_rect.x() + 10, _rect.y(), fm.width(_status_text), _rect.height()) painter.drawText(_status_rect, QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter, _status_text) painter.setPen( QtGui.QPen(QtGui.QColor(_status_handle.data()["Color"]), 1)) painter.drawLine(_status_rect.x() + _status_rect.width() + 10, _rect.y() + _rect.height() / 2.0, _rect.x() + _rect.width(), _rect.y() + _rect.height() / 2.0)
def paintEvent(self, event): painter = QtGui.QPainter(self) metrics = QtGui.QFontMetrics(self.font()) elided = metrics.elidedText(self.text(), QtCore.Qt.ElideRight, self.width()) painter.drawText(self.rect(), self.alignment(), elided)
def _drawValue(self, painter, value, position, state): size = self.size() color = QtGui.QColor( 120, 120, 120) if state == state.DisabledState else QtGui.QColor( 240, 220, 40) painter.setPen(color) # Draw vertical line at position ensuring we don't clip it # at the edges of the widget. lineWidth = 2 position = max( min(int(position) - (lineWidth / 2), size.x - lineWidth), 0) painter.fillRect(position, 0, lineWidth, size.y, color) # Draw frame number to the left of the playhead (unless we'd go off the # edge). Most cursors are pointing to the left so this makes it easier # to read the number when hovering. font = painter.font() font.setPixelSize(10) painter.setFont(font) frameText = GafferUI.NumericWidget.valueToString(value) frameTextSize = QtGui.QFontMetrics(painter.font()).size( QtCore.Qt.TextSingleLine, frameText) textMargin = 6 textX = position - frameTextSize.width() - textMargin if textX < textMargin: textX = position + textMargin painter.drawText(textX, frameTextSize.height(), frameText)
def updateCompleteList(self, lines=None, extra=None): self.clear() if lines or extra: self.showMe() if lines: for i in [x for x in lines if not x.name == 'mro']: item = QtWidgets.QListWidgetItem(i.name) item.setData(32, i) self.addItem(item) if extra: font = self.font() font.setItalic(1) font.setPointSize(font.pointSize() * 0.8) for e in extra: item = QtWidgets.QListWidgetItem(e.name) item.setData(32, e) item.setFont(font) self.addItem(item) font = QtGui.QFont("monospace", self.lineHeight, False) fm = QtGui.QFontMetrics(font) width = fm.width(' ') * max([len(x.name) for x in lines or extra]) + 40 self.resize(max(250, width), 250) self.setCurrentRow(0) else: self.hideMe()
def draw_attributes(self, painter): """Draw attributes for this node. Called exclusively by paint. :param painter: painter from paint. :type painter: QtGui.QPainter """ for attr_name in self.user_attr_names: # draw bg rect attr_details = self._attribute_draw_details[attr_name] painter.setBrush(attr_details['bg_color']) painter.setPen(QtCore.Qt.NoPen) painter.drawRect(attr_details['bg_rect']) # draw connection points target_color = attr_details['plug_color'] self._attr_plug_graphics.setdefault(attr_name, {}) attr_plug_graphics = self._attr_plug_graphics[attr_name] current_in_plug = attr_plug_graphics.get('in_plug') in_pos = self.get_attr_in_pos(attr_name, scene=False) if current_in_plug: current_in_plug.setPos(in_pos) current_in_plug.color = target_color current_in_plug.update() else: in_plug = NodeGraphicsPlug(pos=in_pos, radius=self.ATTR_PLUG_RADIUS, color=target_color, attr_name_represented=attr_name, is_input=True) attr_plug_graphics['in_plug'] = in_plug in_plug.setParentItem(self) current_out_plug = attr_plug_graphics.get('out_plug') out_pos = self.get_attr_out_pos(attr_name, scene=False) if current_out_plug: current_out_plug.setPos(out_pos) current_out_plug.color = target_color current_out_plug.update() else: out_plug = NodeGraphicsPlug(pos=out_pos, radius=self.ATTR_PLUG_RADIUS, color=target_color, attr_name_represented=attr_name, is_input=False) attr_plug_graphics['out_plug'] = out_plug out_plug.setParentItem(self) # draw attr_name painter.setPen(attr_details['title_color']) painter.setFont(attr_details['title_font']) rect = attr_details['bg_rect'] font_metrics = QtGui.QFontMetrics(self.attr_font) title = font_metrics.elidedText(attr_name, QtCore.Qt.ElideRight, self.max_width - 20) painter.drawText(rect.x() + 10, rect.y() - 1, rect.width(), rect.height(), QtCore.Qt.AlignVCenter, title)
def asValuePin(pin, painter, option, widget): lod = pin.owningNode().canvasRef().getCanvasLodValueFromCurrentScale() SWITCH_LOD = editableStyleSheet().PinSwitch[0] frame = QtCore.QRectF(QtCore.QPointF(0, 0), pin.geometry().size()) w = frame.width() / 2 h = frame.height() / 2 halfPinSize = pin.pinSize / 2 if lod < SWITCH_LOD and not pin.bLabelHidden: painter.setFont(pin._font) textWidth = QtGui.QFontMetrics(painter.font()).width( pin.displayName()) textHeight = QtGui.QFontMetrics(painter.font()).height() x = 1 + pin.pinSize + halfPinSize if pin.direction == PinDirection.Output: x = frame.width() - textWidth - pin.pinSize - 1 yCenter = textHeight - textHeight / 3 painter.setPen(QtGui.QPen(pin.labelColor, 0.5, QtCore.Qt.SolidLine)) painter.drawText(x, yCenter, pin.displayName()) pinCenter = pin.pinCenter() radialGrad = QtGui.QRadialGradient(pinCenter.x(), pinCenter.y() - 0.3, halfPinSize * 0.8) if not pin._rawPin.hasConnections(): radialGrad.setColorAt(0, pin.color().darker(280)) radialGrad.setColorAt(0.5, pin.color().darker(280)) radialGrad.setColorAt(0.65, pin.color().lighter(130)) radialGrad.setColorAt(1, pin.color().lighter(70)) else: radialGrad.setColorAt(0, pin.color()) radialGrad.setColorAt(1, pin.color()) painter.setPen(QtCore.Qt.NoPen) if pin.hovered: radialGrad.setColorAt(1, pin.color().lighter(200)) painter.setBrush(QtGui.QColor(128, 128, 128, 30)) painter.drawRoundedRect(frame, 3, 3) painter.setBrush(radialGrad) painter.drawEllipse(pinCenter.x() - halfPinSize, pinCenter.y() - halfPinSize, pin.pinSize, pin.pinSize)
def __init__(self): super(outputClass, self).__init__() self.setWordWrapMode(QtGui.QTextOption.NoWrap) self.fs = 14 self.document().setDefaultFont( QtGui.QFont("monospace", self.fs, QtGui.QFont.Normal)) metrics = QtGui.QFontMetrics(self.document().defaultFont()) self.setTabStopWidth(4 * metrics.width(' ')) self.setMouseTracking(1)
def __init__(self, parent=None): super(ItemDelegate, self).__init__(parent) self._spacing = 8 self._font = QtGui.QFont("Microsoft YaHei UI", 9) self._font.setPixelSize(10) self._font.setBold(True) self._font_metrics = QtGui.QFontMetrics(self._font)
def add_label_item(self, label, node_id): item = QtGui.QStandardItem(label) item.setToolTip(node_id) metrics = QtGui.QFontMetrics(item.font()) width = metrics.horizontalAdvance(item.text()) + 30 item.setSizeHint(QtCore.QSize(width, 20)) self.model().appendRow(item) self.selectionModel().setCurrentIndex( self.model().indexFromItem(item), QtCore.QItemSelectionModel.ClearAndSelect)
def paint(self, painter, option, index): painter.save() rect = option.rect font_matrics = QtGui.QFontMetrics(option.font) report_name = index.data(model.DisplayRole) painter.fillRect(rect, self.getBackgroudColor(option, index)) painter.drawText(rect.x() + 5, rect.y() + 15, report_name) painter.restore()
def getTextDimensions(item): """ Find the width and hieght of the text label of the item :param item: :return width, height: """ font = item.property('font') metric = QtGui.QFontMetrics(font) width = metric.width(item.text()) height = metric.ascent() return width, height
def __init__(self, text=None, parent=None, shadow=True, color=(150, 150, 150)): QtWidgets.QWidget.__init__(self, parent) self.setMinimumHeight(2) self.setLayout(QtWidgets.QHBoxLayout()) self.layout().setContentsMargins(0, 0, 0, 0) self.layout().setSpacing(0) self.layout().setAlignment(QtCore.Qt.AlignVCenter) first_line = QtWidgets.QFrame() first_line.setFrameStyle(QtWidgets.QFrame.HLine) self.layout().addWidget(first_line) main_color = 'rgba( %s, %s, %s, 255)' % color shadow_color = 'rgba( 45, 45, 45, 255)' bottom_border = '' if shadow: bottom_border = 'border-bottom:1px solid %s;' % shadow_color style_sheet = "border:0px solid rgba(0,0,0,0); \ background-color: %s; \ max-height:1px; \ %s" % (main_color, bottom_border) first_line.setStyleSheet(style_sheet) if text is None: return first_line.setMaximumWidth(5) font = QtGui.QFont() font.setBold(True) text_width = QtGui.QFontMetrics(font) width = text_width.width(text) + 6 label = QtWidgets.QLabel() label.setText(text) label.setFont(font) label.setMaximumWidth(width) label.setAlignment(QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter) self.layout().addWidget(label) second_line = QtWidgets.QFrame() second_line.setFrameStyle(QtWidgets.QFrame.HLine) second_line.setStyleSheet(style_sheet) self.layout().addWidget(second_line)
def setColormap(self, foovalue=None): P = self.view2DProp a = self.viewer.colormapActionGroup.checkedAction() self.displayBox.displayColormap.setText(a.text()) # Use a rescale icon iconwidth = 105 - QtGui.QFontMetrics(QtGui.QFont()).width(a.text()) icon = QtGui.QIcon(a.icon().pixmap(64, 64).scaled(iconwidth, 12)) self.displayBox.displayColormap.setIcon(icon) self.displayBox.displayColormap.setIconSize(QtCore.QSize( iconwidth, 12)) P["colormapText"] = a.text()
def __init__(self, *args, **kwargs): super(CustomCheck, self).__init__(*args, **kwargs) font = qg.QFont() font.setPointSize(12) font.setFamily('Calibri') self.setFont(font) self.setFixedHeight(27) font.setLetterSpacing(QFont.AbsoluteSpacing, float(self._spacing)) self.fontMetrics = qg.QFontMetrics(font) self.radius = 5
def __init__(self, borderRad=20, *args, **kwargs): super(Custom_button, self).__init__(*args, **kwargs) self.setStyleSheet("background: transparent;") self.radius = borderRad font = qg.QFont() font.setPointSize(self._fontSize) font.setFamily('Calibri') font.setLetterSpacing(QFont.AbsoluteSpacing, float(self._spacing)) font.setBold(True) self.setFont(font) self.fontMetrics = qg.QFontMetrics(font)
def __init__(self): super(outputClass, self).__init__() self.setWordWrapMode(QtGui.QTextOption.NoWrap) font = QtGui.QFont("Courier") font.setStyleHint(QtGui.QFont.Monospace) font.setFixedPitch(True) self.setFont(font) self.fs = 14 self.document().setDefaultFont( QtGui.QFont("monospace", self.fs, QtGui.QFont.Normal)) metrics = QtGui.QFontMetrics(self.document().defaultFont()) self.setTabStopWidth(4 * metrics.width(' ')) self.setMouseTracking(1)
def paint(self, painter, option, index): painter.save() rect = option.rect font_matrics = QtGui.QFontMetrics(option.font) karte_name = index.data(model.DisplayRole) painter.fillRect(rect, self.getBackgroudColor(option, index)) painter.drawPixmap(QtCore.QRect(rect.x() + 10, rect.y(), 50, 50), self.__karte_icon) painter.drawText( rect.x() + 80, rect.y() + rect.height() * 0.5 + font_matrics.height() * 0.5 - 4, karte_name) painter.restore()
def update_selector_btn(self): """ Update the button appearance following the selection by the user of the files to post. """ file_to_post = os.path.basename(self.post_path) self.file_selector_btn.setToolTip(file_to_post) font_metrics = QtGui.QFontMetrics(self.file_selector_btn.font()) elided_text = font_metrics.elidedText( file_to_post, QtCore.Qt.ElideRight, self.file_selector_btn.width() - 5, ) self.file_selector_btn.setText(elided_text)
def conformFormLayoutLabels(self, parentObject, padding=8): """ Conform the widths of all labels in formLayouts under the specified parentObject for a more coherent appearance. 'padding' is an amount in pixels to add to the max width. """ labels = [] labelWidths = [] # Find all labels in form layouts for layout in parentObject.findChildren(QtWidgets.QFormLayout): # print(layout.objectName()) items = (layout.itemAt(i) for i in range(layout.count())) for item in items: widget = item.widget() if isinstance(widget, QtWidgets.QLabel): labels.append(widget) # Find labels in first column of grid layouts for layout in parentObject.findChildren(QtWidgets.QGridLayout): # print(layout.objectName()) items = (layout.itemAt(i) for i in range(layout.count())) for item in items: widget = item.widget() if isinstance(widget, QtWidgets.QLabel): # Only items in first column (there's probably a neater # way to do this) if layout.getItemPosition(layout.indexOf(widget))[1] == 0: labels.append(widget) # Find label widths for label in labels: fontMetrics = QtGui.QFontMetrics(label.font()) width = fontMetrics.width(label.text()) #print('Width of "%s": %d px' %(label.text(), width)) labelWidths.append(width) # Get widest label & set all labels widths to match if labelWidths: maxWidth = max(labelWidths) #print("Max label width : %d px (%d inc padding)" %(maxWidth, maxWidth+padding)) for label in labels: label.setFixedWidth(maxWidth + padding) label.setAlignment(QtCore.Qt.AlignVCenter | QtCore.Qt.AlignRight) label.setProperty('formLabel', True) # Set custom property for styling
def create_header(self, dict_cols): """ Create the header and set its visual aspect. """ self.setHorizontalHeaderLabels(dict_cols.values()) self.horizontalHeader().setHighlightSections(False) self.horizontalHeader().setSectionsClickable(False) self.horizontalHeader().setDefaultAlignment(QtCore.Qt.AlignLeft) stylesheet = ("QHeaderView::section{color:" + self.text_color + "; font-weight: bold; font-size: 18px}") self.horizontalHeader().setStyleSheet(stylesheet) font = self.horizontalHeader().font() font.setBold(True) font.setPointSize(14) self.horizontalHeader().setFont(font) height = QtGui.QFontMetrics( self.horizontalHeader().fontMetrics()).height() self.horizontalHeader().setFixedHeight(1.3 * height)
def _paint_active(self, painter, option, status_item): _rect = option.rect painter.setPen(QtGui.QPen(QtGui.QColor(0, 0, 0, 0), 0)) painter.setBrush( QtGui.QColor(constants.Constants.STATUS_BACKGROUND_COLOR)) painter.drawRoundedRect(option.rect, 1, 1) fm = QtGui.QFontMetrics(painter.font()) painter.setPen(QtGui.QPen(QtGui.QColor("#A5A6A8"), 1)) _status_text = u"激活 · active" _status_rect = QtCore.QRectF(_rect.x() + 10, _rect.y(), fm.width(_status_text), _rect.height()) painter.drawText(_status_rect, QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter, _status_text) painter.setPen(QtGui.QPen(QtGui.QColor("#A5A6A8"), 1)) painter.drawLine(_status_rect.x() + _status_rect.width() + 10, _rect.y() + _rect.height() / 2.0, _rect.x() + _rect.width(), _rect.y() + _rect.height() / 2.0)
def __init__(self, parent, desk=None): # https://github.com/davidhalter/jedi # http://jedi.jedidjah.ch/en/latest/ super(inputClass, self).__init__(parent) self.p = parent self.desk = desk self.setWordWrapMode(QtGui.QTextOption.NoWrap) self.document().setDefaultFont( QtGui.QFont(font_name, minimumFontSize, QtGui.QFont.Normal)) metrics = QtGui.QFontMetrics(self.document().defaultFont()) self.setTabStopWidth(4 * metrics.width(' ')) self.setAcceptDrops(True) self.fs = 12 self.completer = completeWidget.completeMenuClass(parent, self) # self.setContextMenuPolicy(Qt.CustomContextMenu) # self.customContextMenuRequested.connect(self.openMenu) data = settingsManager.scriptEditorClass().readSettings() self.applyHightLighter(data.get('theme')) # self.changeFontSize(False) self.changeFontSize(True)
def update_header_task_name(self): self.header_task_entity_name.update() seq_name = self.task["sequence_name"] if seq_name: ep_name = self.task["episode_name"] if ep_name: full_entity_name = "{}/{}/{}".format(ep_name, seq_name, self.task["entity_name"]) else: full_entity_name = "{}/{}".format(seq_name, self.task["entity_name"]) else: full_entity_name = "{}/{}".format(self.task["entity_type_name"], self.task["entity_name"]) font_metrics = QtGui.QFontMetrics(self.header_task_entity_name.font()) elided_text = font_metrics.elidedText( full_entity_name, QtCore.Qt.ElideRight, self.header_task_entity_name.width(), ) self.header_task_entity_name.setToolTip(full_entity_name) self.header_task_entity_name.setText(elided_text)
def paint(self, painter, option, index): painter.save() rect = option.rect font_matrics = QtGui.QFontMetrics(option.font) tester_name = index.data(model.DisplayRole) status = index.data(model.StatusRole) if status == model.Ready: icon = self.__ready_icon elif status == model.Success: icon = self.__success_icon elif status == model.Failure: icon = self.__failure_icon painter.fillRect(rect, self.getBackgroudColor(option, index)) painter.drawPixmap(QtCore.QRect(rect.x() + 12, rect.y() + 2, 16, 16), icon) painter.drawText( rect.x() + 40, rect.y() + rect.height() * 0.5 + font_matrics.height() * 0.5 - 4, tester_name) painter.restore()
def paintEvent(self, event): _model = self.model() if _model: if isinstance(_model, QtCore.QSortFilterProxyModel): _model = _model.sourceModel() if not _model or not _model.rowCount(): _rect = self.rect() painter = QtGui.QPainter() painter.begin(self.viewport()) painter.setRenderHint(QtGui.QPainter.Antialiasing, True) _font = QtGui.QFont("Microsoft YaHei UI", 8) _font.setPixelSize(24) _font.setBold(True) painter.setFont(_font) _pen = QtGui.QPen(QtGui.QColor("#CACACA"), 1, QtCore.Qt.SolidLine) _pen.setWidth(0.1) painter.setPen(_pen) fm = QtGui.QFontMetrics(_font) painter.drawText(_rect, QtCore.Qt.AlignCenter, u"暂无数据") painter.end() return super(ListView, self).paintEvent(event)