我们从Python开源项目中,提取了以下13个代码示例,用于说明如何使用PyQt5.QtCore.Qt.NoBrush()。
def drawWidget(self, qp): font = QFont('Sans', 11, QFont.Normal) qp.setFont(font) pen = QPen(QColor(20, 20, 20), 1, Qt.SolidLine) qp.setPen(pen) qp.setBrush(Qt.NoBrush) if self.value==True: qp.setBrush(QColor(95,163,235)) qp.drawRoundedRect(0, 0.0, 80.0,22.0,5.0,5.0) qp.setBrush(QColor(230,230,230)) qp.drawRoundedRect(40, 2, 38,18.0,5.0,5.0) qp.drawText(8, 17, _("ON")) else: qp.setBrush(QColor(180,180,180)) qp.drawRoundedRect(0, 0.0, 80.0,22.0,5.0,5.0) qp.setBrush(QColor(230,230,230)) qp.drawRoundedRect(2, 2, 38,18.0,5.0,5.0) qp.drawText(44, 17, _("OFF"))
def drawOutline(self, painter): painter.setPen(Qt.darkGreen) painter.setPen(Qt.DashLine) painter.setBrush(Qt.NoBrush) painter.drawRect(0, 0, 100, 100)
def _assemble_plot(self, qpainter): qpainter.save() #--- # draw bounding box qpainter.setPen(self._bbox_pen) qpainter.setBrush(self._bbox_brush) qpainter.drawRect(self._bbox_rect) # x-axis qpainter.setFont(self._labelFont) qpainter.setPen(self._axes_tick_pen) qpainter.setBrush(self._axes_tick_brush) for tick_line in self._xaxis_ticks: qpainter.drawLine(tick_line) for i in range(len(self._xaxis_ticks_text)): qpainter.drawText(self._xaxis_ticks_text_rect[i], Qt.AlignVCenter | Qt.AlignHCenter, self._xaxis_ticks_text[i]) # y-axis for tick_line in self._yaxis_ticks: qpainter.drawLine(tick_line) for i in range(len(self._yaxis_ticks_text)): qpainter.drawText(self._yaxis_ticks_text_rect[i], Qt.AlignVCenter | Qt.AlignHCenter, self._yaxis_ticks_text[i]) # x-axis origin qpainter.setPen(self._axes_origin_pen) qpainter.setBrush(self._axes_origin_brush) if self._xaxis_origin_x > self._bbox_x0 and self._xaxis_origin_x < self._bbox_x1: qpainter.drawLine(self._xaxis_origin_line) # y-axis origin if self._yaxis_origin_y > self._bbox_y0 and self._yaxis_origin_y < self._bbox_y1: qpainter.drawLine(self._yaxis_origin_line) # draw plots for plot_key in self._plot_points.keys(): qpainter.setPen(self._plot_pens[plot_key]) qpainter.setBrush(QBrush(Qt.NoBrush)) if self._plot_draw_method[plot_key] == 'line' and len(self._plot_points[plot_key]) > 1: qpainter.drawPolyline(QPolygonF(self._plot_points[plot_key])) else: for plot_point in self._plot_points[plot_key]: qpainter.drawPoint(plot_point) #--- qpainter.restore() # G E T T E R S / S E T T E R S #===========================================================================
def paintEvent(self, event): painter = QPainter(self) painter.setRenderHint(QPainter.Antialiasing) width = self.width() - 8 height = 36 previous = 0 percent_up = 0 for partition in self.partitions: color = self.color_list[self.partitions.index(partition)] percent = self.__percentage(width, partition.getSize(), self.max_capacity) if percent < 10: percent += 4 percent_up += 1 if percent_up >= 0 and percent >= width/35: percent -= 4 * percent_up percent_up = 0 print(percent, width) painter.setPen(color) painter.setBrush(color) painter.drawRect(QRectF(4+previous, 5, percent, 34)) previous += percent #Çerçeve painter.setPen(QColor(Qt.black)) painter.setBrush(Qt.NoBrush) painter.drawRoundedRect(QRectF(4, 4, width, height), 4, 4) #Parlakl?k painter.drawPixmap(QRect(6, 6, width-4, height-4), QPixmap(":/images/partitionwidget/light.svg")) #kareler line = 0 column = 0 for partition in self.partitions: painter.setPen(Qt.black) painter.setBrush(self.color_list[self.partitions.index(partition)]) if width - (line * 150) <= 150: column += 1 line = 0 painter.drawRoundedRect(QRectF(4 + (line * 150), (column*32)+64, 12, 12), 2, 2) painter.drawText(QRectF(24 + (line * 150), (column*32)+64, 30, 12), Qt.AlignVCenter | Qt.TextDontClip, partition.path) painter.setPen(Qt.darkGray) if partition.fileSystem: painter.drawText(QRectF(24 + (line * 150), (column*32)+78, 40, 12), Qt.AlignVCenter | Qt.TextDontClip, "{} {}".format(mbToGB(partition.getSize()), partition.fileSystem.type)) else: painter.drawText(QRectF(24 + (line * 150), (column*32)+78, 40, 12), Qt.AlignVCenter | Qt.TextDontClip, self.tr("{} Bilinmiyor").format(mbToGB(partition.getSize()))) line += 1
def paintEvent(self, event): rect = QRect(10, 20, 80, 60) path = QPainterPath() path.moveTo(20, 80) path.lineTo(20, 30) path.cubicTo(80, 0, 50, 50, 80, 80) startAngle = 30 * 16 arcLength = 120 * 16 painter = QPainter(self) painter.setPen(self.pen) painter.setBrush(self.brush) if self.antialiased: painter.setRenderHint(QPainter.Antialiasing) for x in range(0, self.width(), 100): for y in range(0, self.height(), 100): painter.save() painter.translate(x, y) if self.transformed: painter.translate(50, 50) painter.rotate(60.0) painter.scale(0.6, 0.9) painter.translate(-50, -50) if self.shape == RenderArea.Line: painter.drawLine(rect.bottomLeft(), rect.topRight()) elif self.shape == RenderArea.Points: painter.drawPoints(RenderArea.points) elif self.shape == RenderArea.Polyline: painter.drawPolyline(RenderArea.points) elif self.shape == RenderArea.Polygon: painter.drawPolygon(RenderArea.points) elif self.shape == RenderArea.Rect: painter.drawRect(rect) elif self.shape == RenderArea.RoundedRect: painter.drawRoundedRect(rect, 25, 25, Qt.RelativeSize) elif self.shape == RenderArea.Ellipse: painter.drawEllipse(rect) elif self.shape == RenderArea.Arc: painter.drawArc(rect, startAngle, arcLength) elif self.shape == RenderArea.Chord: painter.drawChord(rect, startAngle, arcLength) elif self.shape == RenderArea.Pie: painter.drawPie(rect, startAngle, arcLength) elif self.shape == RenderArea.Path: painter.drawPath(path) elif self.shape == RenderArea.Text: painter.drawText(rect, Qt.AlignCenter, "PyQt by\nRiverbank Computing") elif self.shape == RenderArea.Pixmap: painter.drawPixmap(10, 10, self.pixmap) painter.restore() painter.setPen(self.palette().dark().color()) painter.setBrush(Qt.NoBrush) painter.drawRect(QRect(0, 0, self.width() - 1, self.height() - 1))
def openFile(self, svg_file): if not svg_file.exists(): return s = self.scene() if self.backgroundItem: drawBackground = self.backgroundItem.isVisible() else: drawBackground = False if self.outlineItem: drawOutline = self.outlineItem.isVisible() else: drawOutline = True s.clear() self.resetTransform() self.svgItem = QGraphicsSvgItem(svg_file.fileName()) self.svgItem.setFlags(QGraphicsItem.ItemClipsToShape) self.svgItem.setCacheMode(QGraphicsItem.NoCache) self.svgItem.setZValue(0) self.backgroundItem = QGraphicsRectItem(self.svgItem.boundingRect()) self.backgroundItem.setBrush(Qt.white) self.backgroundItem.setPen(QPen(Qt.NoPen)) self.backgroundItem.setVisible(drawBackground) self.backgroundItem.setZValue(-1) self.outlineItem = QGraphicsRectItem(self.svgItem.boundingRect()) outline = QPen(Qt.black, 2, Qt.DashLine) outline.setCosmetic(True) self.outlineItem.setPen(outline) self.outlineItem.setBrush(QBrush(Qt.NoBrush)) self.outlineItem.setVisible(drawOutline) self.outlineItem.setZValue(1) s.addItem(self.backgroundItem) s.addItem(self.svgItem) s.addItem(self.outlineItem) s.setSceneRect(self.outlineItem.boundingRect().adjusted(-10, -10, 10, 10))
def _draw_widget(self, qp): font = QFont('Serif', 7, QFont.Light) qp.setFont(font) size = self.size() w = size.width() h = size.height() pen = QPen(QColor(180, 180, 180), 3, Qt.SolidLine) qp.setPen(pen) qp.drawLine(1, h - 5, w - 1, h - 5) span = self.maximum() - self.minimum() if span == 0: x = 1 else: x = (w - 2) * (self.value() - self.minimum()) / span + 1 pen = QPen(QColor(130, 130, 130), 3, Qt.SolidLine) qp.setPen(pen) pen = QPen(QColor(0, 0, 0), 3, Qt.SolidLine) qp.drawLine(1, h - 5, x, h - 5) qp.setPen(pen) qp.drawLine(x, h - 5, x, h - 5) # # qp.setPen(pen) # qp.setBrush(Qt.NoBrush) # qp.drawRect(0, 0, w-1, h-1) # # j = 0 # # for i in range(step, 10*step, step): # # qp.drawLine(i, 0, i, 5) # metrics = qp.fontMetrics() # fw = metrics.width(str(self.num[j])) # qp.drawText(i-fw/2, h/2, str(self.num[j])) # j = j + 1 for marker in self._markers: marker.draw(qp)