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"))
python类SolidLine()的实例源码
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 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_drop_indicator(self, painter):
if self.drag_active:
opt = QStyleOption()
opt.initFrom(self)
opt.rect = self.drop_indicator_rect
rect = opt.rect
brush = QBrush(QColor(Qt.darkRed))
if rect.height() == 0:
pen = QPen(brush, 2, Qt.SolidLine)
painter.setPen(pen)
painter.drawLine(rect.topLeft(), rect.topRight())
else:
pen = QPen(brush, 2, Qt.SolidLine)
painter.setPen(pen)
painter.drawRect(rect)
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 pen(self, color=Qt.black, style=Qt.SolidLine):
pen = QPen(color)
pen.setStyle(style)
return pen
def paint(self, painter: QPainter, option: QStyleOptionViewItem, index: QModelIndex) -> None:
r = option.rect
pencolor = Qt.white if self.theme == 'dark' else Qt.black
if self.parent.isEnabled():
if option.state & QStyle.State_Selected:
painter.setBrush(QColor(150, 190, 78, 150))
elif option.state & QStyle.State_MouseOver:
painter.setBrush(QColor(227, 212, 232))
pencolor = Qt.black
else:
brushcolor = QColor(79, 85, 87, 175) if self.theme == 'dark' else QColor('#EFF0F1')
painter.setBrush(Qt.transparent if index.row() % 2 == 0 else brushcolor)
painter.setPen(Qt.NoPen)
painter.drawRect(r)
thumb = QIcon(index.data(Qt.DecorationRole + 1))
starttime = index.data(Qt.DisplayRole + 1)
endtime = index.data(Qt.UserRole + 1)
externalPath = index.data(Qt.UserRole + 2)
r = option.rect.adjusted(5, 0, 0, 0)
thumb.paint(painter, r, Qt.AlignVCenter | Qt.AlignLeft)
painter.setPen(QPen(pencolor, 1, Qt.SolidLine))
r = option.rect.adjusted(110, 8, 0, 0)
painter.setFont(QFont('Noto Sans UI', 10 if sys.platform == 'darwin' else 8, QFont.Bold))
painter.drawText(r, Qt.AlignLeft, 'FILENAME' if len(externalPath) else 'START')
r = option.rect.adjusted(110, 20, 0, 0)
painter.setFont(QFont('Noto Sans UI', 11 if sys.platform == 'darwin' else 9, QFont.Normal))
if len(externalPath):
painter.drawText(r, Qt.AlignLeft, self.clipText(os.path.basename(externalPath), painter))
else:
painter.drawText(r, Qt.AlignLeft, starttime)
if len(endtime) > 0:
r = option.rect.adjusted(110, 45, 0, 0)
painter.setFont(QFont('Noto Sans UI', 10 if sys.platform == 'darwin' else 8, QFont.Bold))
painter.drawText(r, Qt.AlignLeft, 'RUNTIME' if len(externalPath) else 'END')
r = option.rect.adjusted(110, 60, 0, 0)
painter.setFont(QFont('Noto Sans UI', 11 if sys.platform == 'darwin' else 9, QFont.Normal))
painter.drawText(r, Qt.AlignLeft, endtime)
if self.parent.verticalScrollBar().isVisible():
self.parent.setFixedWidth(210)
else:
self.parent.setFixedWidth(190)
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 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 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 paint_pause_indicator(self, painter):
if self.show_pause_active:
rect = self.__rect_for_row(self.pause_row)
brush = QBrush(QColor(Qt.darkGreen))
pen = QPen(brush, 2, Qt.SolidLine)
painter.setPen(pen)
painter.drawLine(rect.topLeft(), rect.topRight())
def draw(self, qp):
size = self._media_progress_widget.size()
w = size.width()
h = size.height()
pen = QPen(QColor(100, 100, 100), 1,
Qt.SolidLine)
qp.setPen(pen)
font = QFont('Serif', 10, QFont.Light)
qp.setFont(font)
metrics = qp.fontMetrics()
text_width = metrics.width(self.name)
text_height = metrics.height()
text_left = (w - 2 - text_width) * self.progress + 1
qp.drawText(text_left, text_height, self.name)
left = (w - 2) * self.progress + 1
qp.drawLine(left, text_height + 3, left, h - 4)
if self.progress > 0.5:
qp.drawLine(text_left, text_height + 3, left, text_height + 3)
else:
qp.drawLine(left, text_height + 3, text_left + text_width, text_height + 3)
self.left = text_left
self.right = self.left + text_width
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 _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)