本文整理匯總了Python中qwt.painter.QwtPainter類的典型用法代碼示例。如果您正苦於以下問題:Python QwtPainter類的具體用法?Python QwtPainter怎麽用?Python QwtPainter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了QwtPainter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: legendIcon
def legendIcon(self, index, size):
if size.isEmpty():
return QwtGraphic()
graphic = QwtGraphic()
graphic.setDefaultSize(size)
graphic.setRenderHint(QwtGraphic.RenderPensUnscaled, True)
painter = QPainter(graphic)
painter.setRenderHint(QPainter.Antialiasing,
self.testRenderHint(QwtPlotItem.RenderAntialiased))
if self.__data.legendAttributes == 0 or\
(self.__data.legendAttributes & QwtPlotCurve.LegendShowBrush):
brush = self.__data.brush
if brush.style() == Qt.NoBrush and self.__data.legendAttributes == 0:
if self.style() != QwtPlotCurve.NoCurve:
brush = QBrush(self.pen().color())
elif self.__data.symbol and\
self.__data.symbol.style() != QwtSymbol.NoSymbol:
brush = QBrush(self.__data.symbol.pen().color())
if brush.style() != Qt.NoBrush:
r = QRectF(0, 0, size.width(), size.height())
painter.fillRect(r, brush)
if self.__data.legendAttributes & QwtPlotCurve.LegendShowLine:
if self.pen() != Qt.NoPen:
pn = self.pen()
# pn.setCapStyle(Qt.FlatCap)
painter.setPen(pn)
y = .5*size.height()
QwtPainter.drawLine(painter, 0., y, size.width(), y)
if self.__data.legendAttributes & QwtPlotCurve.LegendShowSymbol:
if self.__data.symbol:
r = QRectF(0, 0, size.width(), size.height())
self.__data.symbol.drawSymbol(painter, r)
return graphic
示例2: renderLegend
def renderLegend(self, painter, rect, fillBackground):
if self.__data.itemMap.isEmpty():
return
if fillBackground:
if self.autoFillBackground() or\
self.testAttribute(Qt.WA_StyledBackground):
QwtPainter.drawBackground(painter, rect, self)
# const QwtDynGridLayout *legendLayout =
# qobject_cast<QwtDynGridLayout *>( contentsWidget()->layout() );
#TODO: not the exact same implementation
legendLayout = self.__data.view.contentsWidget.layout()
if legendLayout is None:
return
left, right, top, bottom = self.getContentsMargins()
layoutRect = QRect()
layoutRect.setLeft(np.ceil(rect.left())+left)
layoutRect.setTop(np.ceil(rect.top())+top)
layoutRect.setRight(np.ceil(rect.right())-right)
layoutRect.setBottom(np.ceil(rect.bottom())-bottom)
numCols = legendLayout.columnsForWidth(layoutRect.width())
itemRects = legendLayout.layoutItems(layoutRect, numCols)
index = 0
for i in range(legendLayout.count()):
item = legendLayout.itemAt(i)
w = item.widget()
if w is not None:
painter.save()
painter.setClipRect(itemRects[index], Qt.IntersectClip)
self.renderItem(painter, w, itemRects[index], fillBackground)
index += 1
painter.restore()
示例3: draw
def draw(self, painter, rect):
if self.__data.paintAttributes & self.PaintBackground:
if self.__data.borderPen != Qt.NoPen or\
self.__data.backgroundBrush != Qt.NoBrush:
painter.save()
painter.setPen(self.__data.borderPen)
painter.setBrush(self.__data.backgroundBrush)
if self.__data.borderRadius == 0:
QwtPainter.drawRect(painter, rect)
else:
painter.setRenderHint(QPainter.Antialiasing, True)
painter.drawRoundedRect(rect, self.__data.borderRadius,
self.__data.borderRadius)
painter.restore()
painter.save()
if self.__data.paintAttributes & self.PaintUsingTextFont:
painter.setFont(self.__data.font)
if self.__data.paintAttributes & self.PaintUsingTextColor:
if self.__data.color.isValid():
painter.setPen(self.__data.color)
expandedRect = rect
if self.__data.layoutAttributes & self.MinimumLayout:
font = QFont(painter.font(), self.desktopwidget)
(left, right, top, bottom
) = self.__data.textEngine.textMargins(font)
expandedRect.setTop(rect.top()-top)
expandedRect.setBottom(rect.bottom()+bottom)
expandedRect.setLeft(rect.left()-left)
expandedRect.setRight(rect.right()+right)
self.__data.textEngine.draw(painter, expandedRect,
self.__data.renderFlags, self.__data.text)
painter.restore()
示例4: qwtDrawTriangleSymbols
def qwtDrawTriangleSymbols(painter, type, points, numPoint, symbol):
size =symbol.size()
pen = QPen(symbol.pen())
pen.setJoinStyle(Qt.MiterJoin)
painter.setPen(pen)
painter.setBrush(symbol.brush())
doAlign = QwtPainter.roundingAlignment(painter)
sw2 = .5*size.width()
sh2 = .5*size.height()
if doAlign:
sw2 = np.floor(sw2)
sh2 = np.floor(sh2)
for pos in points:
x = pos.x()
y = pos.y()
if doAlign:
x = round(x)
y = round(y)
x1 = x-sw2
x2 = x1+size.width()
y1 = y-sh2
y2 = y1+size.height()
if type == QwtTriangle.Left:
triangle = [QPointF(x2, y1), QPointF(x1, y), QPointF(x2, y2)]
elif type == QwtTriangle.Right:
triangle = [QPointF(x1, y1), QPointF(x2, y), QPointF(x1, y2)]
elif type == QwtTriangle.Up:
triangle = [QPointF(x1, y2), QPointF(x, y1), QPointF(x2, y2)]
elif type == QwtTriangle.Down:
triangle = [QPointF(x1, y1), QPointF(x, y2), QPointF(x2, y1)]
QwtPainter.drawPolygon(painter, QPolygonF(triangle))
示例5: drawLines
def drawLines(self, painter, canvasRect, pos):
"""
Draw the lines marker
:param QPainter painter: Painter
:param QRectF canvasRect: Contents rectangle of the canvas in painter coordinates
:param QPointF pos: Position of the marker, translated into widget coordinates
.. seealso::
:py:meth:`drawLabel()`,
:py:meth:`qwt.symbol.QwtSymbol.drawSymbol()`
"""
if self.__data.style == self.NoLine:
return
doAlign = QwtPainter.roundingAlignment(painter)
painter.setPen(self.__data.pen)
if self.__data.style in (QwtPlotMarker.HLine, QwtPlotMarker.Cross):
y = pos.y()
if doAlign:
y = round(y)
QwtPainter.drawLine(painter, canvasRect.left(),
y, canvasRect.right()-1., y)
if self.__data.style in (QwtPlotMarker.VLine, QwtPlotMarker.Cross):
x = pos.x()
if doAlign:
x = round(x)
QwtPainter.drawLine(painter, x,
canvasRect.top(), x, canvasRect.bottom()-1.)
示例6: qwtDrawRectSymbols
def qwtDrawRectSymbols(painter, points, numPoints, symbol):
size = symbol.size()
pen = QPen(symbol.pen())
pen.setJoinStyle(Qt.MiterJoin)
painter.setPen(pen)
painter.setBrush(symbol.brush())
painter.setRenderHint(QPainter.Antialiasing, False)
if QwtPainter.roundingAlignment(painter):
sw = size.width()
sh = size.height()
sw2 = size.width()//2
sh2 = size.height()//2
for pos in points:
x = round(pos.x())
y = round(pos.y())
r = QRectF(x-sw2, y-sh2, sw, sh)
QwtPainter.drawRect(painter, r)
else:
sw = size.width()
sh = size.height()
sw2 = .5*size.width()
sh2 = .5*size.height()
for pos in points:
x = pos.x()
y = pos.y()
r = QRectF(x-sw2, y-sh2, sw, sh)
QwtPainter.drawRect(painter, r)
示例7: renderItem
def renderItem(self, painter, widget, rect, fillBackground):
"""
Render a legend entry into a given rectangle.
:param QPainter painter: Painter
:param QWidget widget: Widget representing a legend entry
:param QRectF rect: Bounding rectangle
:param bool fillBackground: When true, fill rect with the widget background
"""
if fillBackground:
if widget.autoFillBackground() or\
widget.testAttribute(Qt.WA_StyledBackground):
QwtPainter.drawBackground(painter, rect, widget)
label = widget #TODO: cast to QwtLegendLabel
if label is not None:
icon = label.data().icon()
sz = icon.defaultSize()
iconRect = QRectF(rect.x()+label.margin(),
rect.center().y()-.5*sz.height(),
sz.width(), sz.height())
icon.render(painter, iconRect, Qt.KeepAspectRatio)
titleRect = QRectF(rect)
titleRect.setX(iconRect.right()+2*label.spacing())
painter.setFont(label.font())
painter.setPen(label.palette().color(QPalette.Text))
label.drawText(painter, titleRect) #TODO: cast label to QwtLegendLabel
示例8: qwtDrawDiamondSymbols
def qwtDrawDiamondSymbols(painter, points, numPoints, symbol):
size =symbol.size()
pen = QPen(symbol.pen())
pen.setJoinStyle(Qt.MiterJoin)
painter.setPen(pen)
painter.setBrush(symbol.brush())
if QwtPainter.roundingAlignment(painter):
for pos in points:
x = round(pos.x())
y = round(pos.y())
x1 = x-size.width()//2
y1 = y-size.height()//2
x2 = x1+size.width()
y2 = y1+size.height()
polygon = QPolygonF()
polygon += QPointF(x, y1)
polygon += QPointF(x1, y)
polygon += QPointF(x, y2)
polygon += QPointF(x2, y)
QwtPainter.drawPolygon(painter, polygon)
else:
for pos in points:
x1 = pos.x()-.5*size.width()
y1 = pos.y()-.5*size.height()
x2 = x1+size.width()
y2 = y1+size.height()
polygon = QPolygonF()
polygon += QPointF(pos.x(), y1)
polygon += QPointF(x1, pos.y())
polygon += QPointF(pos.x(), y2)
polygon += QPointF(x2, pos.y())
QwtPainter.drawPolygon(painter, polygon)
示例9: qwtDrawHexagonSymbols
def qwtDrawHexagonSymbols(painter, points, numPoints, symbol):
painter.setBrush(symbol.brush())
painter.setPen(symbol.pen())
cos30 = np.cos(30*np.pi/180.)
dx = .5*(symbol.size().width()-cos30)
dy = .25*symbol.size().height()
doAlign = QwtPainter.roundingAlignment(painter)
for pos in points:
if doAlign:
x = round(pos.x())
y = round(pos.y())
x1 = np.ceil(x-dx)
y1 = np.ceil(y-2*dy)
else:
x = pos.x()
y = pos.y()
x1 = x-dx
y1 = y-2*dy
x2 = x1+1*dx
x3 = x1+2*dx
y2 = y1+1*dy
y3 = y1+3*dy
y4 = y1+4*dy
hexa = [QPointF(x2, y1), QPointF(x3, y2), QPointF(x3, y3),
QPointF(x2, y4), QPointF(x1, y3), QPointF(x1, y2)]
QwtPainter.drawPolygon(painter, QPolygonF(hexa))
示例10: fillCurve
def fillCurve(self, painter, xMap, yMap, canvasRect, polygon):
"""
Fill the area between the curve and the baseline with
the curve brush
:param QPainter painter: Painter
:param qwt.scale_map.QwtScaleMap xMap: Maps x-values into pixel coordinates.
:param qwt.scale_map.QwtScaleMap yMap: Maps y-values into pixel coordinates.
:param QRectF canvasRect: Contents rectangle of the canvas
:param QPolygonF polygon: Polygon - will be modified !
.. seealso::
:py:meth:`setBrush()`, :py:meth:`setBaseline()`,
:py:meth:`setStyle()`
"""
if self.__data.brush.style() == Qt.NoBrush:
return
self.closePolyline(painter, xMap, yMap, polygon)
if polygon.count() <= 2:
return
brush = self.__data.brush
if not brush.color().isValid():
brush.setColor(self.__data.pen.color())
if self.__data.paintAttributes & self.ClipPolygons:
polygon = QwtClipper().clipPolygonF(canvasRect, polygon, True)
painter.save()
painter.setPen(Qt.NoPen)
painter.setBrush(brush)
QwtPainter.drawPolygon(painter, polygon)
painter.restore()
示例11: drawColorBar
def drawColorBar(self, painter, rect):
if not self.__data.colorBar.interval.isValid():
return
sd = self.__data.scaleDraw
QwtPainter.drawColorBar(painter, self.__data.colorBar.colorMap,
self.__data.colorBar.interval.normalized(),
sd.scaleMap(), sd.orientation(), rect)
示例12: legendIcon
def legendIcon(self, index, size):
"""
:param int index: Index of the legend entry (ignored as there is only one)
:param QSizeF size: Icon size
:return: Icon representing the marker on the legend
.. seealso::
:py:meth:`qwt.plot.QwtPlotItem.setLegendIconSize()`,
:py:meth:`qwt.plot.QwtPlotItem.legendData()`
"""
if size.isEmpty():
return QwtGraphic()
icon = QwtGraphic()
icon.setDefaultSize(size)
icon.setRenderHint(QwtGraphic.RenderPensUnscaled, True)
painter = QPainter(icon)
painter.setRenderHint(QPainter.Antialiasing,
self.testRenderHint(QwtPlotItem.RenderAntialiased))
if self.__data.style != QwtPlotMarker.NoLine:
painter.setPen(self.__data.pen)
if self.__data.style in (QwtPlotMarker.HLine, QwtPlotMarker.Cross):
y = .5*size.height()
QwtPainter.drawLine(painter, 0., y, size.width(), y)
if self.__data.style in (QwtPlotMarker.VLine, QwtPlotMarker.Cross):
x = .5*size.width()
QwtPainter.drawLine(painter, x, 0., x, size.height())
if self.__data.symbol:
r = QRect(0, 0, size.width(), size.height())
self.__data.symbol.drawSymbol(painter, r)
return icon
示例13: drawBorder
def drawBorder(self, painter):
if self.__data.borderRadius > 0:
if self.frameWidth() > 0:
QwtPainter.drawRoundedFrame(painter, QRectF(self.frameRect()),
self.__data.borderRadius, self.__data.borderRadius,
self.palette(), self.frameWidth(), self.frameStyle())
else:
if QT_VERSION >= 0x040500:
if PYQT5:
from qwt.qt.QtGui import QStyleOptionFrame
else:
from qwt.qt.QtGui import QStyleOptionFrameV3 as\
QStyleOptionFrame
opt = QStyleOptionFrame()
opt.initFrom(self)
frameShape = self.frameStyle() & QFrame.Shape_Mask
frameShadow = self.frameStyle() & QFrame.Shadow_Mask
opt.frameShape = QFrame.Shape(int(opt.frameShape)|frameShape)
if frameShape in (QFrame.Box, QFrame.HLine, QFrame.VLine,
QFrame.StyledPanel, QFrame.Panel):
opt.lineWidth = self.lineWidth()
opt.midLineWidth = self.midLineWidth()
else:
opt.lineWidth = self.frameWidth()
if frameShadow == self.Sunken:
opt.state |= QStyle.State_Sunken
elif frameShadow == self.Raised:
opt.state |= QStyle.State_Raised
self.style().drawControl(QStyle.CE_ShapedFrame, opt, painter, self)
else:
self.drawFrame(painter)
示例14: drawSteps
def drawSteps(self, painter, xMap, yMap, canvasRect, from_, to):
doAlign = QwtPainter.roundingAlignment(painter)
polygon = QPolygonF(2*(to-from_)+1)
inverted = self.orientation() == Qt.Vertical
if self.__data.attributes & self.Inverted:
inverted = not inverted
series = self.data()
ip = 0
for i in range(from_, to+1):
sample = series.sample(i)
xi = xMap.transform(sample.x())
yi = yMap.transform(sample.y())
if doAlign:
xi = round(xi)
yi = round(yi)
if ip > 0:
p0 = polygon[ip-2]
if inverted:
polygon[ip-1] = QPointF(p0.x(), yi)
else:
polygon[ip-1] = QPointF(xi, p0.y())
polygon[ip] = QPointF(xi, yi)
ip += 2
if self.__data.paintAttributes & self.ClipPolygons:
clipped = QwtClipper().clipPolygonF(canvasRect, polygon, False)
QwtPainter.drawPolyline(painter, clipped)
else:
QwtPainter.drawPolyline(painter, polygon)
if self.__data.brush.style() != Qt.NoBrush:
self.fillCurve(painter, xMap, yMap, canvasRect, polygon)
示例15: draw
def draw(self, painter, rect, flags, text):
"""
Draw the text in a clipping rectangle
:param QPainter painter: Painter
:param QRectF rect: Clipping rectangle
:param int flags: Bitwise OR of the flags like in for QPainter::drawText()
:param str text: Text to be rendered
"""
QwtPainter.drawText(painter, rect, flags, text)