本文整理汇总了Python中qwt.qt.QtCore.QRectF类的典型用法代码示例。如果您正苦于以下问题:Python QRectF类的具体用法?Python QRectF怎么用?Python QRectF使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QRectF类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: 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
示例2: drawLines
def drawLines(self, painter, xMap, yMap, canvasRect, from_, to):
"""
Draw lines
: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 int from_: Index of the first point to be painted
:param int to: Index of the last point to be painted. If to < 0 the curve will be painted to its last point.
.. seealso::
:py:meth:`draw()`, :py:meth:`drawDots()`,
:py:meth:`drawSteps()`, :py:meth:`drawSticks()`
"""
if from_ > to:
return
doAlign = QwtPainter.roundingAlignment(painter)
doFill = self.__data.brush.style() != Qt.NoBrush\
and self.__data.brush.color().alpha() > 0
clipRect = QRectF()
if self.__data.paintAttributes & self.ClipPolygons:
pw = max([1., painter.pen().widthF()])
clipRect = canvasRect.adjusted(-pw, -pw, pw, pw)
doIntegers = False
if QT_VERSION < 0x040800:
if painter.paintEngine().type() == QPaintEngine.Raster:
if not doFill:
doIntegers = True
noDuplicates = self.__data.paintAttributes & self.FilterPoints
mapper = QwtPointMapper()
mapper.setFlag(QwtPointMapper.RoundPoints, doAlign)
mapper.setFlag(QwtPointMapper.WeedOutPoints, noDuplicates)
mapper.setBoundingRect(canvasRect)
if doIntegers:
polyline = mapper.toPolygon(xMap, yMap, self.data(), from_, to)
if self.__data.paintAttributes & self.ClipPolygons:
polyline = QwtClipper().clipPolygon(clipRect.toAlignedRect(),
polyline, False)
QwtPainter.drawPolyline(painter, polyline)
else:
polyline = mapper.toPolygonF(xMap, yMap, self.data(), from_, to)
if doFill:
if painter.pen().style() != Qt.NoPen:
filled = QPolygonF(polyline)
self.fillCurve(painter, xMap, yMap, canvasRect, filled)
filled.clear()
if self.__data.paintAttributes & self.ClipPolygons:
polyline = QwtClipper().clipPolygonF(clipRect,
polyline, False)
QwtPainter.drawPolyline(painter, polyline)
else:
self.fillCurve(painter, xMap, yMap, canvasRect, polyline)
else:
if self.__data.paintAttributes & self.ClipPolygons:
polyline = QwtClipper().clipPolygonF(clipRect, polyline,
False)
QwtPainter.drawPolyline(painter, polyline)
示例3: minLabelDist
def minLabelDist(self, font):
if not self.hasComponent(QwtAbstractScaleDraw.Labels):
return 0
ticks = self.scaleDiv().ticks(QwtScaleDiv.MajorTick)
if not ticks:
return 0
fm = QFontMetrics(font)
vertical = self.orientation() == Qt.Vertical
bRect1 = QRectF()
bRect2 = self.labelRect(font, ticks[0])
if vertical:
bRect2.setRect(-bRect2.bottom(), 0.,
bRect2.height(), bRect2.width())
maxDist = 0.
for tick in ticks:
bRect1 = bRect2
bRect2 = self.labelRect(font, tick)
if vertical:
bRect2.setRect(-bRect2.bottom(), 0.,
bRect2.height(), bRect2.width())
dist = fm.leading()
if bRect1.right() > 0:
dist += bRect1.right()
if bRect2.left() < 0:
dist += -bRect2.left()
if dist > maxDist:
maxDist = dist
angle = qwtRadians(self.labelRotation())
if vertical:
angle += np.pi/2
sinA = np.sin(angle)
if qFuzzyCompare(sinA+1., 1.):
return np.ceil(maxDist)
fmHeight = fm.ascent()-2
labelDist = fmHeight/np.sin(angle)*np.cos(angle)
if labelDist < 0:
labelDist = -labelDist
if labelDist > maxDist:
labelDist = maxDist
if labelDist < fmHeight:
labelDist = fmHeight
return np.ceil(labelDist)
示例4: drawPath
def drawPath(self, path):
rect = QRectF(QPointF(0., 0.), self.__size)
if path.controlPointRect().contains(rect.center()):
self.setCornerRects(path)
self.alignCornerRects(rect)
self.background.path = path
self.background.brush = self.__brush
self.background.origin = self.__origin
else:
self.border.pathlist += [path]
示例5: renderDocument
def renderDocument(self, plot, filename, sizeMM=(300, 200), resolution=85,
format_=None):
if isinstance(sizeMM, tuple):
sizeMM = QSizeF(*sizeMM)
if format_ is None:
ext = osp.splitext(filename)[1]
if not ext:
raise TypeError("Unable to determine target format from filename")
format_ = ext[1:]
if plot is None or sizeMM.isEmpty() or resolution <= 0:
return
title = plot.title().text()
if not title:
title = "Plot Document"
mmToInch = 1./25.4
size = sizeMM * mmToInch * resolution
documentRect = QRectF(0.0, 0.0, size.width(), size.height())
fmt = format_.lower()
if fmt in ("pdf", "ps"):
printer = QPrinter()
if fmt == "pdf":
printer.setOutputFormat(QPrinter.PdfFormat)
else:
printer.setOutputFormat(QPrinter.PostScriptFormat)
printer.setColorMode(QPrinter.Color)
printer.setFullPage(True)
printer.setPaperSize(sizeMM, QPrinter.Millimeter)
printer.setDocName(title)
printer.setOutputFileName(filename)
printer.setResolution(resolution)
painter = QPainter(printer)
self.render(plot, painter, documentRect)
painter.end()
elif fmt == "svg":
generator = QSvgGenerator()
generator.setTitle(title)
generator.setFileName(filename)
generator.setResolution(resolution)
generator.setViewBox(documentRect)
painter = QPainter(generator)
self.render(plot, painter, documentRect)
painter.end()
elif fmt in QImageWriter.supportedImageFormats():
imageRect = documentRect.toRect()
dotsPerMeter = int(round(resolution*mmToInch*1000.))
image = QImage(imageRect.size(), QImage.Format_ARGB32)
image.setDotsPerMeterX(dotsPerMeter)
image.setDotsPerMeterY(dotsPerMeter)
image.fill(QColor(Qt.white).rgb())
painter = QPainter(image)
self.render(plot, painter, imageRect)
painter.end()
image.save(filename, fmt)
else:
raise TypeError("Unsupported file format '%s'" % fmt)
示例6: drawSymbol
def drawSymbol(self, painter, point_or_rect):
"""
Draw the symbol into a rectangle
The symbol is painted centered and scaled into the target rectangle.
It is always painted uncached and the pin point is ignored.
This method is primarily intended for drawing a symbol to the legend.
:param QPainter painter: Painter
:param point_or_rect: Position or target rectangle of the symbol in screen coordinates
:type point_or_rect: QPointF or QPoint or QRectF
"""
if isinstance(point_or_rect, (QPointF, QPoint)):
# drawSymbol( QPainter *, const QPointF & )
self.drawSymbols(painter, [point_or_rect])
return
# drawSymbol( QPainter *, const QRectF & )
rect = point_or_rect
assert isinstance(rect, QRectF)
if self.__data.style == QwtSymbol.NoSymbol:
return
if self.__data.style == QwtSymbol.Graphic:
self.__data.graphic.graphic.render(painter, rect,
Qt.KeepAspectRatio)
elif self.__data.style == QwtSymbol.Path:
if self.__data.path.graphic.isNull():
self.__data.path.graphic = qwtPathGraphic(
self.__data.path.path, self.__data.pen, self.__data.brush)
self.__data.path.graphic.render(painter, rect, Qt.KeepAspectRatio)
return
elif self.__data.style == QwtSymbol.SvgDocument:
if self.__data.svg.renderer is not None:
scaledRect = QRectF()
sz = QSizeF(self.__data.svg.renderer.viewBoxF().size())
if not sz.isEmpty():
sz.scale(rect.size(), Qt.KeepAspectRatio)
scaledRect.setSize(sz)
scaledRect.moveCenter(rect.center())
else:
scaledRect = rect
self.__data.svg.renderer.render(painter, scaledRect)
else:
br = QRect(self.boundingRect())
ratio = min([rect.width()/br.width(), rect.height()/br.height()])
painter.save()
painter.translate(rect.center())
painter.scale(ratio, ratio)
isPinPointEnabled = self.__data.isPinPointEnabled
self.__data.isPinPointEnabled = False
pos = QPointF()
self.renderSymbols(painter, pos, 1)
self.__data.isPinPointEnabled = isPinPointEnabled
painter.restore()
示例7: draw
def draw(self, painter, xMap, yMap, canvasRect):
pos = QPointF(xMap.transform(self.__data.xValue),
yMap.transform(self.__data.yValue))
self.drawLines(painter, canvasRect, pos)
if self.__data.symbol and\
self.__data.symbol.style() != QwtSymbol.NoSymbol:
sz = self.__data.symbol.size()
clipRect = QRectF(canvasRect.adjusted(-sz.width(), -sz.height(),
sz.width(), sz.height()))
if clipRect.contains(pos):
self.__data.symbol.drawSymbols(painter, [pos])
self.drawLabel(painter, canvasRect, pos)
示例8: toRect
def toRect(self):
r = QRectF(self.hInterval.minValue(), self.vInterval.minValue(),
self.hInterval.maxValue()-self.hInterval.minValue(),
self.vInterval.maxValue()-self.vInterval.minValue())
r = r.normalized()
if self.hInterval.borderFlags() & QwtInterval.ExcludeMinimum:
r.adjust(1, 0, 0, 0)
if self.hInterval.borderFlags() & QwtInterval.ExcludeMaximum:
r.adjust(0, 0, -1, 0)
if self.vInterval.borderFlags() & QwtInterval.ExcludeMinimum:
r.adjust(0, 1, 0, 0)
if self.vInterval.borderFlags() & QwtInterval.ExcludeMaximum:
r.adjust(0, 0, 0, -1)
return r
示例9: drawLines
def drawLines(self, painter, xMap, yMap, canvasRect, from_, to):
if from_ > to:
return
doAlign = QwtPainter.roundingAlignment(painter)
doFit = (self.__data.attributes & self.Fitted)\
and self.__data.curveFitter
doFill = self.__data.brush.style() != Qt.NoBrush\
and self.__data.brush.color().alpha() > 0
clipRect = QRectF()
if self.__data.paintAttributes & self.ClipPolygons:
pw = max([1., painter.pen().widthF()])
clipRect = canvasRect.adjusted(-pw, -pw, pw, pw)
doIntegers = False
if QT_VERSION < 0x040800:
if painter.paintEngine().type() == QPaintEngine.Raster:
if not doFit and not doFill:
doIntegers = True
noDuplicates = self.__data.paintAttributes & self.FilterPoints
mapper = QwtPointMapper()
mapper.setFlag(QwtPointMapper.RoundPoints, doAlign)
mapper.setFlag(QwtPointMapper.WeedOutPoints, noDuplicates)
mapper.setBoundingRect(canvasRect)
if doIntegers:
polyline = mapper.toPolygon(xMap, yMap, self.data(), from_, to)
if self.__data.paintAttributes & self.ClipPolygons:
polyline = QwtClipper().clipPolygon(clipRect.toAlignedRect(),
polyline, False)
QwtPainter.drawPolyline(painter, polyline)
else:
polyline = mapper.toPolygonF(xMap, yMap, self.data(), from_, to)
if doFit:
polyline = self.__data.curveFitter.fitCurve(polyline)
if doFill:
if painter.pen().style() != Qt.NoPen:
filled = QPolygonF(polyline)
self.fillCurve(painter, xMap, yMap, canvasRect, filled)
filled.clear()
if self.__data.paintAttributes & self.ClipPolygons:
polyline = QwtClipper().clipPolygonF(clipRect,
polyline, False)
QwtPainter.drawPolyline(painter, polyline)
else:
self.fillCurve(painter, xMap, yMap, canvasRect, polyline)
else:
if self.__data.paintAttributes & self.ClipPolygons:
polyline = QwtClipper().clipPolygonF(clipRect, polyline,
False)
QwtPainter.drawPolyline(painter, polyline)
示例10: renderItem
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
示例11: drawSymbol
def drawSymbol(self, painter, point_or_rect):
if isinstance(point_or_rect, (QPointF, QPoint)):
# drawSymbol( QPainter *, const QPointF & )
self.drawSymbols(painter, [point_or_rect], 1)
return
# drawSymbol( QPainter *, const QRectF & )
rect = point_or_rect
assert isinstance(rect, QRectF)
if self.__data.style == QwtSymbol.NoSymbol:
return
if self.__data.style == QwtSymbol.Graphic:
self.__data.graphic.graphic.render(painter, rect,
Qt.KeepAspectRatio)
elif self.__data.style == QwtSymbol.Path:
if self.__data.path.graphic.isNull():
self.__data.path.graphic = qwtPathGraphic(
self.__data.path.path, self.__data.pen, self.__data.brush)
self.__data.path.graphic.render(painter, rect, Qt.KeepAspectRatio)
return
elif self.__data.style == QwtSymbol.SvgDocument:
if self.__data.svg.renderer is not None:
scaledRect = QRectF()
sz = QSizeF(self.__data.svg.renderer.viewBoxF().size())
if not sz.isEmpty():
sz.scale(rect.size(), Qt.KeepAspectRatio)
scaledRect.setSize(sz)
scaledRect.moveCenter(rect.center())
else:
scaledRect = rect
self.__data.svg.renderer.render(painter, scaledRect)
else:
br = QRect(self.boundingRect())
ratio = min([rect.width()/br.width(), rect.height()/br.height()])
painter.save()
painter.translate(rect.center())
painter.scale(ratio, ratio)
isPinPointEnabled = self.__data.isPinPointEnabled
self.__data.isPinPointEnabled = False
pos = QPointF()
self.renderSymbols(painter, pos, 1)
self.__data.isPinPointEnabled = isPinPointEnabled
painter.restore()
示例12: draw
def draw(self, painter, xMap, yMap, canvasRect):
"""
Draw the marker
:param QPainter painter: Painter
:param qwt.scale_map.QwtScaleMap xMap: x Scale Map
:param qwt.scale_map.QwtScaleMap yMap: y Scale Map
:param QRectF canvasRect: Contents rectangle of the canvas in painter coordinates
"""
pos = QPointF(xMap.transform(self.__data.xValue),
yMap.transform(self.__data.yValue))
self.drawLines(painter, canvasRect, pos)
if self.__data.symbol and\
self.__data.symbol.style() != QwtSymbol.NoSymbol:
sz = self.__data.symbol.size()
clipRect = QRectF(canvasRect.adjusted(-sz.width(), -sz.height(),
sz.width(), sz.height()))
if clipRect.contains(pos):
self.__data.symbol.drawSymbols(painter, [pos])
self.drawLabel(painter, canvasRect, pos)
示例13: drawSimpleRichText
def drawSimpleRichText(self, painter, rect, flags, text):
txt = text.clone()
painter.save()
unscaledRect = QRectF(rect)
if painter.font().pixelSize() < 0:
res = qwtScreenResolution()
pd = painter.device()
if pd.logicalDpiX() != res.width()\
or pd.logicalDpiY() != res.height():
transform = QTransform()
transform.scale(res.width()/float(pd.logicalDpiX()),
res.height()/float(pd.logicalDpiY()))
painter.setWorldTransform(transform, True)
invtrans, _ok = transform.inverted()
unscaledRect = invtrans.mapRect(rect)
txt.setDefaultFont(painter.font())
txt.setPageSize(QSizeF(unscaledRect.width(), QWIDGETSIZE_MAX))
layout = txt.documentLayout()
height = layout.documentSize().height()
y = unscaledRect.y()
if flags & Qt.AlignBottom:
y += unscaledRect.height()-height
elif flags & Qt.AlignVCenter:
y += (unscaledRect.height()-height)/2
context = QAbstractTextDocumentLayout.PaintContext()
context.palette.setColor(QPalette.Text, painter.pen().color())
painter.translate(unscaledRect.x(), y)
layout.draw(painter, context)
painter.restore()
示例14: qwtDrawGraphicSymbols
def qwtDrawGraphicSymbols(painter, points, numPoint, graphic, symbol):
pointRect = QRectF(graphic.controlPointRect())
if pointRect.isEmpty():
return
sx = 1.
sy = 1.
sz = symbol.size()
if sz.isValid():
sx = sz.width()/pointRect.width()
sy = sz.height()/pointRect.height()
pinPoint = QPointF(pointRect.center())
if symbol.isPinPointEnabled():
pinPoint = symbol.pinPoint()
transform = QTransform(painter.transform())
for pos in points:
tr = QTransform(transform)
tr.translate(pos.x(), pos.y())
tr.scale(sx, sy)
tr.translate(-pinPoint.x(), -pinPoint.y())
painter.setTransform(tr)
graphic.render(painter)
painter.setTransform(transform)
示例15: invTransform
def invTransform(self, *args):
"""Transform from paint to scale coordinates
Scalar: scalemap.invTransform(scalar)
Point (QPointF): scalemap.invTransform(xMap, yMap, pos)
Rectangle (QRectF): scalemap.invTransform(xMap, yMap, rect)
"""
if len(args) == 1:
# Scalar transform
return self.invTransform_scalar(args[0])
elif isinstance(args[2], QPointF):
xMap, yMap, pos = args
return QPointF(xMap.invTransform(pos.x()),
yMap.invTransform(pos.y()))
elif isinstance(args[2], QRectF):
xMap, yMap, rect = args
x1 = xMap.invTransform(rect.left())
x2 = xMap.invTransform(rect.right()-1)
y1 = yMap.invTransform(rect.top())
y2 = yMap.invTransform(rect.bottom()-1)
r = QRectF(x1, y1, x2-x1, y2-y1)
return r.normalized()