本文整理汇总了Python中qwt.painter.QwtPainter.drawBackground方法的典型用法代码示例。如果您正苦于以下问题:Python QwtPainter.drawBackground方法的具体用法?Python QwtPainter.drawBackground怎么用?Python QwtPainter.drawBackground使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qwt.painter.QwtPainter
的用法示例。
在下文中一共展示了QwtPainter.drawBackground方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: renderItem
# 需要导入模块: from qwt.painter import QwtPainter [as 别名]
# 或者: from qwt.painter.QwtPainter import drawBackground [as 别名]
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
示例2: renderLegend
# 需要导入模块: from qwt.painter import QwtPainter [as 别名]
# 或者: from qwt.painter.QwtPainter import drawBackground [as 别名]
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: renderItem
# 需要导入模块: from qwt.painter import QwtPainter [as 别名]
# 或者: from qwt.painter.QwtPainter import drawBackground [as 别名]
def renderItem(self, painter, widget, rect, fillBackground):
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
示例4: renderCanvas
# 需要导入模块: from qwt.painter import QwtPainter [as 别名]
# 或者: from qwt.painter.QwtPainter import drawBackground [as 别名]
def renderCanvas(self, plot, painter, canvasRect, maps):
canvas = plot.canvas()
r = canvasRect.adjusted(0., 0., -1., 1.)
if self.__data.layoutFlags & self.FrameWithScales:
painter.save()
r.adjust(-1., -1., 1., 1.)
painter.setPen(QPen(Qt.black))
if not (self.__data.discardFlags & self.DiscardCanvasBackground):
bgBrush = canvas.palette().brush(plot.backgroundRole())
painter.setBrush(bgBrush)
QwtPainter.drawRect(painter, r)
painter.restore()
painter.save()
painter.setClipRect(canvasRect)
plot.drawItems(painter, canvasRect, maps)
painter.restore()
elif canvas.testAttribute(Qt.WA_StyledBackground):
clipPath = QPainterPath()
painter.save()
if not self.__data.discardFlags & self.DiscardCanvasBackground:
QwtPainter.drawBackground(painter, r, canvas)
clipPath = qwtCanvasClip(canvas, canvasRect)
painter.restore()
painter.save()
if clipPath.isEmpty():
painter.setClipRect(canvasRect)
else:
painter.setClipPath(clipPath)
plot.drawItems(painter, canvasRect, maps)
painter.restore()
else:
clipPath = QPainterPath()
frameWidth = 0
if not self.__data.discardFlags & self.DiscardCanvasFrame:
frameWidth = canvas.frameWidth()
clipPath = qwtCanvasClip(canvas, canvasRect)
innerRect = canvasRect.adjusted(frameWidth, frameWidth,
-frameWidth, -frameWidth)
painter.save()
if clipPath.isEmpty():
painter.setClipRect(innerRect)
else:
painter.setClipPath(clipPath)
if not self.__data.discardFlags & self.DiscardCanvasBackground:
QwtPainter.drawBackground(painter, innerRect, canvas)
plot.drawItems(painter, innerRect, maps)
painter.restore()
if frameWidth > 0:
painter.save()
frameStyle = canvas.frameShadow() | canvas.frameShape()
frameWidth = canvas.frameWidth()
borderRadius = canvas.borderRadius()
if borderRadius > 0.:
QwtPainter.drawRoundedFrame(painter, canvasRect, r, r,
canvas.palette(), frameWidth,
frameStyle)
else:
midLineWidth = canvas.midLineWidth()
QwtPainter.drawFrame(painter, canvasRect, canvas.palette(),
canvas.foregroundRole(), frameWidth,
midLineWidth, frameStyle)
painter.restore()
示例5: render
# 需要导入模块: from qwt.painter import QwtPainter [as 别名]
# 或者: from qwt.painter.QwtPainter import drawBackground [as 别名]
def render(self, plot, painter, plotRect):
if painter == 0 or not painter.isActive() or not plotRect.isValid()\
or plot.size().isNull():
return
if not self.__data.discardFlags & self.DiscardBackground:
QwtPainter.drawBackground(painter, plotRect, plot)
transform = QTransform()
transform.scale(float(painter.device().logicalDpiX())/plot.logicalDpiX(),
float(painter.device().logicalDpiY())/plot.logicalDpiY())
invtrans, _ok = transform.inverted()
layoutRect = invtrans.mapRect(plotRect)
if not (self.__data.discardFlags & self.DiscardBackground):
left, top, right, bottom = plot.getContentsMargins()
layoutRect.adjust(left, top, -right, -bottom)
layout = plot.plotLayout()
baseLineDists = [None]*QwtPlot.axisCnt
canvasMargins = [None]*QwtPlot.axisCnt
for axisId in range(QwtPlot.axisCnt):
canvasMargins[axisId] = layout.canvasMargin(axisId)
if self.__data.layoutFlags & self.FrameWithScales:
scaleWidget = plot.axisWidget(axisId)
if scaleWidget:
baseLineDists[axisId] = scaleWidget.margin()
scaleWidget.setMargin(0)
if not plot.axisEnabled(axisId):
left, right, top, bottom = 0, 0, 0, 0
if axisId == QwtPlot.yLeft:
layoutRect.adjust(1, 0, 0, 0)
elif axisId == QwtPlot.yRight:
layoutRect.adjust(0, 0, -1, 0)
elif axisId == QwtPlot.xTop:
layoutRect.adjust(0, 1, 0, 0)
elif axisId == QwtPlot.xBottom:
layoutRect.adjust(0, 0, 0, -1)
layoutRect.adjust(left, top, right, bottom)
layoutOptions = QwtPlotLayout.IgnoreScrollbars
if self.__data.layoutFlags & self.FrameWithScales or\
self.__data.discardFlags & self.DiscardCanvasFrame:
layoutOptions |= QwtPlotLayout.IgnoreFrames
if self.__data.discardFlags & self.DiscardLegend:
layoutOptions |= QwtPlotLayout.IgnoreLegend
if self.__data.discardFlags & self.DiscardTitle:
layoutOptions |= QwtPlotLayout.IgnoreTitle
if self.__data.discardFlags & self.DiscardFooter:
layoutOptions |= QwtPlotLayout.IgnoreFooter
layout.activate(plot, layoutRect, layoutOptions)
maps = self.buildCanvasMaps(plot, layout.canvasRect())
if self.updateCanvasMargins(plot, layout.canvasRect(), maps):
layout.activate(plot, layoutRect, layoutOptions)
maps = self.buildCanvasMaps(plot, layout.canvasRect())
painter.save()
painter.setWorldTransform(transform, True)
self.renderCanvas(plot, painter, layout.canvasRect(), maps)
if (not self.__data.discardFlags & self.DiscardTitle) and\
plot.titleLabel().text():
self.renderTitle(plot, painter, layout.titleRect())
if (not self.__data.discardFlags & self.DiscardFooter) and\
plot.titleLabel().text():
self.renderFooter(plot, painter, layout.footerRect())
if (not self.__data.discardFlags & self.DiscardLegend) and\
plot.titleLabel().text():
self.renderLegend(plot, painter, layout.legendRect())
for axisId in range(QwtPlot.axisCnt):
scaleWidget = plot.axisWidget(axisId)
if scaleWidget:
baseDist = scaleWidget.margin()
startDist, endDist = scaleWidget.getBorderDistHint()
self.renderScale(plot, painter, axisId, startDist, endDist,
baseDist, layout.scaleRect(axisId))
painter.restore()
for axisId in range(QwtPlot.axisCnt):
if self.__data.layoutFlags & self.FrameWithScales:
scaleWidget = plot.axisWidget(axisId)
if scaleWidget:
scaleWidget.setMargin(baseLineDists[axisId])
layout.setCanvasMargin(canvasMargins[axisId])
layout.invalidate()
示例6: renderCanvas
# 需要导入模块: from qwt.painter import QwtPainter [as 别名]
# 或者: from qwt.painter.QwtPainter import drawBackground [as 别名]
def renderCanvas(self, plot, painter, canvasRect, maps):
"""
Render the canvas into a given rectangle.
:param qwt.plot.QwtPlot plot: Plot widget
:param QPainter painter: Painter
:param qwt.scale_map.QwtScaleMap maps: mapping between plot and paint device coordinates
:param QRectF rect: Bounding rectangle
"""
canvas = plot.canvas()
r = canvasRect.adjusted(0., 0., -1., 1.)
if self.__data.layoutFlags & self.FrameWithScales:
painter.save()
r.adjust(-1., -1., 1., 1.)
painter.setPen(QPen(Qt.black))
if not (self.__data.discardFlags & self.DiscardCanvasBackground):
bgBrush = canvas.palette().brush(plot.backgroundRole())
painter.setBrush(bgBrush)
painter.drawRect(r)
painter.restore()
painter.save()
painter.setClipRect(canvasRect)
plot.drawItems(painter, canvasRect, maps)
painter.restore()
elif canvas.testAttribute(Qt.WA_StyledBackground):
clipPath = QPainterPath()
painter.save()
if not self.__data.discardFlags & self.DiscardCanvasBackground:
QwtPainter.drawBackground(painter, r, canvas)
clipPath = qwtCanvasClip(canvas, canvasRect)
painter.restore()
painter.save()
if clipPath.isEmpty():
painter.setClipRect(canvasRect)
else:
painter.setClipPath(clipPath)
plot.drawItems(painter, canvasRect, maps)
painter.restore()
else:
clipPath = QPainterPath()
frameWidth = 0
if not self.__data.discardFlags & self.DiscardCanvasFrame:
frameWidth = canvas.frameWidth()
clipPath = qwtCanvasClip(canvas, canvasRect)
innerRect = canvasRect.adjusted(frameWidth, frameWidth,
-frameWidth, -frameWidth)
painter.save()
if clipPath.isEmpty():
painter.setClipRect(innerRect)
else:
painter.setClipPath(clipPath)
if not self.__data.discardFlags & self.DiscardCanvasBackground:
QwtPainter.drawBackground(painter, innerRect, canvas)
plot.drawItems(painter, innerRect, maps)
painter.restore()
if frameWidth > 0:
painter.save()
frameStyle = canvas.frameShadow() | canvas.frameShape()
frameWidth = canvas.frameWidth()
borderRadius = canvas.borderRadius()
if borderRadius > 0.:
QwtPainter.drawRoundedFrame(painter, canvasRect, r, r,
canvas.palette(), frameWidth,
frameStyle)
else:
midLineWidth = canvas.midLineWidth()
QwtPainter.drawFrame(painter, canvasRect, canvas.palette(),
canvas.foregroundRole(), frameWidth,
midLineWidth, frameStyle)
painter.restore()
示例7: render
# 需要导入模块: from qwt.painter import QwtPainter [as 别名]
# 或者: from qwt.painter.QwtPainter import drawBackground [as 别名]
def render(self, plot, painter, plotRect):
"""
Paint the contents of a QwtPlot instance into a given rectangle.
:param qwt.plot.QwtPlot plot: Plot to be rendered
:param QPainter painter: Painter
:param str format: Format for the document
:param QRectF plotRect: Bounding rectangle
.. seealso::
:py:meth:`renderDocument()`, :py:meth:`renderTo()`,
:py:meth:`qwt.painter.QwtPainter.setRoundingAlignment()`
"""
if painter == 0 or not painter.isActive() or not plotRect.isValid()\
or plot.size().isNull():
return
if not self.__data.discardFlags & self.DiscardBackground:
QwtPainter.drawBackground(painter, plotRect, plot)
# The layout engine uses the same methods as they are used
# by the Qt layout system. Therefore we need to calculate the
# layout in screen coordinates and paint with a scaled painter.
transform = QTransform()
transform.scale(float(painter.device().logicalDpiX())/plot.logicalDpiX(),
float(painter.device().logicalDpiY())/plot.logicalDpiY())
invtrans, _ok = transform.inverted()
layoutRect = invtrans.mapRect(plotRect)
if not (self.__data.discardFlags & self.DiscardBackground):
left, top, right, bottom = plot.getContentsMargins()
layoutRect.adjust(left, top, -right, -bottom)
layout = plot.plotLayout()
baseLineDists = [None]*QwtPlot.axisCnt
canvasMargins = [None]*QwtPlot.axisCnt
for axisId in QwtPlot.validAxes:
canvasMargins[axisId] = layout.canvasMargin(axisId)
if self.__data.layoutFlags & self.FrameWithScales:
scaleWidget = plot.axisWidget(axisId)
if scaleWidget:
baseLineDists[axisId] = scaleWidget.margin()
scaleWidget.setMargin(0)
if not plot.axisEnabled(axisId):
left, right, top, bottom = 0, 0, 0, 0
# When we have a scale the frame is painted on
# the position of the backbone - otherwise we
# need to introduce a margin around the canvas
if axisId == QwtPlot.yLeft:
layoutRect.adjust(1, 0, 0, 0)
elif axisId == QwtPlot.yRight:
layoutRect.adjust(0, 0, -1, 0)
elif axisId == QwtPlot.xTop:
layoutRect.adjust(0, 1, 0, 0)
elif axisId == QwtPlot.xBottom:
layoutRect.adjust(0, 0, 0, -1)
layoutRect.adjust(left, top, right, bottom)
# Calculate the layout for the document.
layoutOptions = QwtPlotLayout.IgnoreScrollbars
if self.__data.layoutFlags & self.FrameWithScales or\
self.__data.discardFlags & self.DiscardCanvasFrame:
layoutOptions |= QwtPlotLayout.IgnoreFrames
if self.__data.discardFlags & self.DiscardLegend:
layoutOptions |= QwtPlotLayout.IgnoreLegend
if self.__data.discardFlags & self.DiscardTitle:
layoutOptions |= QwtPlotLayout.IgnoreTitle
if self.__data.discardFlags & self.DiscardFooter:
layoutOptions |= QwtPlotLayout.IgnoreFooter
layout.activate(plot, layoutRect, layoutOptions)
maps = self.buildCanvasMaps(plot, layout.canvasRect())
if self.updateCanvasMargins(plot, layout.canvasRect(), maps):
# recalculate maps and layout, when the margins
# have been changed
layout.activate(plot, layoutRect, layoutOptions)
maps = self.buildCanvasMaps(plot, layout.canvasRect())
painter.save()
painter.setWorldTransform(transform, True)
self.renderCanvas(plot, painter, layout.canvasRect(), maps)
if (not self.__data.discardFlags & self.DiscardTitle) and\
plot.titleLabel().text():
self.renderTitle(plot, painter, layout.titleRect())
if (not self.__data.discardFlags & self.DiscardFooter) and\
plot.titleLabel().text():
self.renderFooter(plot, painter, layout.footerRect())
if (not self.__data.discardFlags & self.DiscardLegend) and\
plot.titleLabel().text():
self.renderLegend(plot, painter, layout.legendRect())
for axisId in QwtPlot.validAxes:
#.........这里部分代码省略.........