我们从Python开源项目中,提取了以下10个代码示例,用于说明如何使用PyQt5.QtCore.Qt.RoundCap()。
def paintEvent(self, event): painter = QPainter(self) painter.setRenderHint(QPainter.Antialiasing) painter.scale(self.width() / 100.0, self.height() / 100.0) painter.translate(50.0, 50.0) painter.rotate(-self.rotationAngle) painter.translate(-50.0, -50.0) painter.setPen( QPen(self.penColor, self.penWidth, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)) gradient = QLinearGradient(0, 0, 0, 100) gradient.setColorAt(0.0, self.fillColor1) gradient.setColorAt(1.0, self.fillColor2) painter.setBrush(QBrush(gradient)) painter.drawPath(self.path)
def paint(self, painter, option, widget): if not self.source or not self.dest: return # Draw the line itself. line = QLineF(self.sourcePoint, self.destPoint) if line.length() == 0.0: return painter.setPen(QPen(Qt.black, 1, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)) painter.drawLine(line) # Draw the arrows if there's enough room. angle = math.acos(line.dx() / line.length()) if line.dy() >= 0: angle = VGraphEdge.TwoPi - angle sourceArrowP1 = self.sourcePoint + QPointF(math.sin(angle + VGraphEdge.Pi / 3) * self.arrowSize, math.cos(angle + VGraphEdge.Pi / 3) * self.arrowSize) sourceArrowP2 = self.sourcePoint + QPointF(math.sin(angle + VGraphEdge.Pi - VGraphEdge.Pi / 3) * self.arrowSize, math.cos(angle + VGraphEdge.Pi - VGraphEdge.Pi / 3) * self.arrowSize); destArrowP1 = self.destPoint + QPointF(math.sin(angle - VGraphEdge.Pi / 3) * self.arrowSize, math.cos(angle - VGraphEdge.Pi / 3) * self.arrowSize) destArrowP2 = self.destPoint + QPointF(math.sin(angle - VGraphEdge.Pi + VGraphEdge.Pi / 3) * self.arrowSize, math.cos(angle - VGraphEdge.Pi + VGraphEdge.Pi / 3) * self.arrowSize) painter.setBrush(Qt.black) painter.drawPolygon(QPolygonF([line.p1(), sourceArrowP1, sourceArrowP2])) painter.drawPolygon(QPolygonF([line.p2(), destArrowP1, destArrowP2]))
def __init__(self, vw, syms, parent, *args, **kwargs): self.vw = vw self.syms = syms QtWidgets.QGraphicsView.__init__(self, parent=parent) e_qt_memory.EnviNavMixin.__init__(self) self.scene = DropGraphicsScene(parent=self) self.setScene(self.scene) self.scene.setStickyFocus(True) self.setDragMode(QtWidgets.QGraphicsView.ScrollHandDrag) self.setBackgroundBrush(QtGui.QBrush(QtGui.QColor(self.bg_color))) self.setViewportUpdateMode(QtWidgets.QGraphicsView.BoundingRectViewportUpdate) self.setRenderHints(self.renderHints() | QtGui.QPainter.Antialiasing | QtGui.QPainter.SmoothPixmapTransform) self._orig_transform = self.transform() self._edge_pen = QtGui.QPen(QtGui.QBrush(QtGui.QColor(self.true_edge_color)), self.edge_width, QtCore.Qt.SolidLine, QtCore.Qt.RoundCap) ################################################################## # Function graph related stuff # holds the memory canvas instances for each basic block self._block_views = dict() self.func_va = None self.func_graph = None # the layout used for this graph self.graph_layout = None self._rend = viv_rend.WorkspaceRenderer(vw)
def init_ui(self): self.pen = QPen() self.pen.setWidth(self.width) self.pen.setJoinStyle(Qt.RoundJoin) self.pen.setCapStyle(Qt.RoundCap) self.setPen(self.pen) self.setFlag(QGraphicsItem.ItemIsMovable) self.setFlag(QGraphicsItem.ItemIsSelectable)
def drawLineTo(self, endPoint): painter = QPainter(self.image) painter.setPen(QPen(self.myPenColor, self.myPenWidth, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)) painter.drawLine(self.lastPoint, endPoint) self.modified = True rad = self.myPenWidth / 2 + 2 self.update(QRect(self.lastPoint, endPoint).normalized().adjusted(-rad, -rad, +rad, +rad)) self.lastPoint = QPoint(endPoint)
def drawWidget(self, qp): color = self.palette().color(QPalette.Background) qp.setBrush(QColor(100,0,0)) pen=QPen() pen.setWidth(self.width()/10) pen.setColor(QColor(0,0,255)) pen.setCapStyle(Qt.RoundCap) w=self.width()/2 x_shift=w+w*0.05 y_shift=w+w*0.05 r=0.35*w r1=w*0.8 qp.setPen(pen) my_max=100 p=[] c=[] for phi in range(0,360,30): p.append(phi) c.append(0) f=0 for i in range(0,len(p)): if p[i]>self.delta: f=i break i=f m=1.0 while(i>=0): c[i]=m m=m*0.7 i=i-1 i=len(c)-1 while(i>f): c[i]=m m=m*0.7 i=i-1 for i in range(0,len(p)): self.pos=p[i] x = r * cos( (2*pi)*self.pos/360 ) y = r * sin( (2*pi)*self.pos/360 ) x1 = r1 * cos( (2*pi)*self.pos/360 ) y1 = r1 * sin( (2*pi)*self.pos/360 ) cb=self.blue_target*c[i]+color.blue()*(1.0-c[i]) cg=self.green_target*c[i]+color.green()*(1.0-c[i]) cr=self.red_target*c[i]+color.red()*(1.0-c[i]) pen.setColor(QColor(cr,cg,cb)) qp.setPen(pen) qp.drawLine(x+x_shift,y+y_shift,x1+x_shift,y1+y_shift)