我们从Python开源项目中,提取了以下3个代码示例,用于说明如何使用PyQt5.QtCore.Qt.DotLine()。
def _add_crosshair(self): """ Adds vertical, horizontal and diagonal crosshairs to the graphic scene """ pen = QPen(self.crosshair_line_color) pen.setWidth(self.line_width) pen.setStyle(Qt.DotLine) width, height = self.width(), self.height() mx, my = self._get_middle() # horizontal self.scene.addLine(0, my, width, my, pen=pen) # vertical self.scene.addLine(mx, 0, mx, height, pen=pen) # 45° self.scene.addLine(0, 0, width, height, pen=pen) self.scene.addLine(width, 0, 0, height, pen=pen)
def drawGlyphBackground(self, painter, glyph, rect, selected=False): if glyph.name == ".notdef": painter.fillRect(QRectF(*rect), self._notdefBackgroundColor) if selected: if self._glyphSelectionColor is not None: selectionColor = self._glyphSelectionColor else: palette = self.palette() active = palette.currentColorGroup() != QPalette.Inactive opacityMultiplier = platformSpecific.colorOpacityMultiplier() selectionColor = palette.color(QPalette.Highlight) selectionColor.setAlphaF( .2 * opacityMultiplier if active else .9) xMin, yMin, width, height = rect painter.save() if self._drawMetrics: pen = painter.pen() pen.setStyle(Qt.DotLine) pen.setColor(self._metricsColor) painter.setPen(pen) drawing.drawLine(painter, xMin, yMin, xMin, yMin + height) drawing.drawLine( painter, xMin + width, yMin, xMin + width, yMin + height) painter.fillRect(xMin, yMin, width, -26, selectionColor) painter.restore()
def _add_circles(self, n, add_text_labels=True): """ Adds n circles to the graphic scene. :param n: the number of circles """ pen = QPen(self.circle_line_color) pen.setStyle(Qt.DotLine) pen.setWidth(self.line_width) width, height = self.width(), self.height() stepw, steph = width/n, height/n mx, my = self._get_middle() for i in range(1, n+1): w, h = width - i * stepw, height - i * steph self.scene.addEllipse((width-w)/2, (height-h)/2, w, h, pen) if add_text_labels: text = QGraphicsTextItem() text.setDefaultTextColor(self.text_label_color) text.setPlainText(str(int(w/2))) text.setPos(mx+w/2.0, my) text2 = QGraphicsTextItem() text2.setDefaultTextColor(self.text_label_color) text2.setPlainText(str(int(-w / 2))) text2.setPos(mx - w / 2.0, my) self.scene.addItem(text) self.scene.addItem(text2)