本文整理匯總了Python中qwt.qt.QtGui.QPainter.end方法的典型用法代碼示例。如果您正苦於以下問題:Python QPainter.end方法的具體用法?Python QPainter.end怎麽用?Python QPainter.end使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類qwt.qt.QtGui.QPainter
的用法示例。
在下文中一共展示了QPainter.end方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: borderPath
# 需要導入模塊: from qwt.qt.QtGui import QPainter [as 別名]
# 或者: from qwt.qt.QtGui.QPainter import end [as 別名]
def borderPath(self, rect):
"""
Calculate the painter path for a styled or rounded border
When the canvas has no styled background or rounded borders
the painter path is empty.
:param QRect rect: Bounding rectangle of the canvas
:return: Painter path, that can be used for clipping
"""
if self.testAttribute(Qt.WA_StyledBackground):
recorder = QwtStyleSheetRecorder(rect.size())
painter = QPainter(recorder)
opt = QStyleOption()
opt.initFrom(self)
opt.rect = rect
self.style().drawPrimitive(QStyle.PE_Widget, opt, painter, self)
painter.end()
if not recorder.background.path.isEmpty():
return recorder.background.path
if not recorder.border.rectList.isEmpty():
return qwtCombinePathList(rect, recorder.border.pathlist)
elif self.__data.borderRadius > 0.:
fw2 = self.frameWidth()*.5
r = QRectF(rect).adjusted(fw2, fw2, -fw2, -fw2)
path = QPainterPath()
path.addRoundedRect(r, self.__data.borderRadius,
self.__data.borderRadius)
return path
return QPainterPath()
示例2: toPixmap
# 需要導入模塊: from qwt.qt.QtGui import QPainter [as 別名]
# 或者: from qwt.qt.QtGui.QPainter import end [as 別名]
def toPixmap(self, *args):
if len(args) == 0:
if self.isNull():
return QPixmap()
sz = self.defaultSize()
w = np.ceil(sz.width())
h = np.ceil(sz.height())
pixmap = QPixmap(w, h)
pixmap.fill(Qt.transparent)
r = QRectF(0., 0., sz.width(), sz.height())
painter = QPainter(pixmap)
self.render(painter, r, Qt.KeepAspectRatio)
painter.end()
return pixmap
elif len(args) in (1, 2):
size = args[0]
aspectRatioMode = Qt.IgnoreAspectRatio
if len(args) == 2:
aspectRatioMode = args[-1]
pixmap = QPixmap(size)
pixmap.fill(Qt.transparent)
r = QRect(0, 0, size.width(), size.height())
painter = QPainter(pixmap)
self.render(painter, r, aspectRatioMode)
painter.end()
return pixmap
示例3: drawColorBar
# 需要導入模塊: from qwt.qt.QtGui import QPainter [as 別名]
# 或者: from qwt.qt.QtGui.QPainter import end [as 別名]
def drawColorBar(self, painter, colorMap, interval, scaleMap,
orientation, rect):
colorTable = []
if colorMap.format() == QwtColorMap.Indexed:
colorTable = colorMap.colorTable(interval)
c = QColor()
devRect = rect.toAlignedRect()
pixmap = QPixmap(devRect.size())
pixmap.fill(Qt.transparent)
pmPainter = QPainter(pixmap)
pmPainter.translate(-devRect.x(), -devRect.y())
if orientation == Qt.Horizontal:
sMap = scaleMap
sMap.setPaintInterval(rect.left(), rect.right())
for x in range(devRect.left(), devRect.right()+1):
value = sMap.invTransform(x)
if colorMap.format() == QwtColorMap.RGB:
c.setRgba(colorMap.rgb(interval, value))
else:
c = colorTable[colorMap.colorIndex(interval, value)]
pmPainter.setPen(c)
pmPainter.drawLine(x, devRect.top(), devRect.bottom())
else:
sMap = scaleMap
sMap.setPaintInterval(rect.bottom(), rect.top())
for y in range(devRect.top(), devRect.bottom()+1):
value = sMap.invTransform(y)
if colorMap.format() == QwtColorMap.RGB:
c.setRgba(colorMap.rgb(interval, value))
else:
c = colorTable[colorMap.colorIndex(interval, value)]
pmPainter.setPen(c)
pmPainter.drawLine(devRect.left(), y, devRect.right(), y)
pmPainter.end()
self.drawPixmap(painter, rect, pixmap)
示例4: toImage
# 需要導入模塊: from qwt.qt.QtGui import QPainter [as 別名]
# 或者: from qwt.qt.QtGui.QPainter import end [as 別名]
def toImage(self, *args):
if len(args) == 0:
if self.isNull():
return QImage()
sz = self.defaultSize()
w = np.ceil(sz.width())
h = np.ceil(sz.height())
image = QImage(w, h, QImage.Format_ARGB32)
image.fill(0)
r = QRect(0, 0, sz.width(), sz.height())
painter = QPainter(image)
self.render(painter, r, Qt.KeepAspectRatio)
painter.end()
return image
elif len(args) in (1, 2):
size = args[0]
aspectRatioMode = Qt.IgnoreAspectRatio
if len(args) == 2:
aspectRatioMode = args[-1]
image = QImage(size, QImage.Format_ARGB32_Premultiplied)
image.fill(0)
r = QRect(0, 0, size.width(), size.height())
painter = QPainter(image)
self.render(painter, r, aspectRatioMode)
return image
示例5: qwtPathGraphic
# 需要導入模塊: from qwt.qt.QtGui import QPainter [as 別名]
# 或者: from qwt.qt.QtGui.QPainter import end [as 別名]
def qwtPathGraphic(path, pen, brush):
graphic = QwtGraphic()
graphic.setRenderHint(QwtGraphic.RenderPensUnscaled)
painter = QPainter(graphic)
painter.setPen(pen)
painter.setBrush(brush)
painter.drawPath(path)
painter.end()
return graphic
示例6: toImage
# 需要導入模塊: from qwt.qt.QtGui import QPainter [as 別名]
# 或者: from qwt.qt.QtGui.QPainter import end [as 別名]
def toImage(self, *args):
"""
.. py:method:: toImage()
Convert the graphic to a `QImage`
All pixels of the image get initialized by 0 ( transparent )
before the graphic is scaled and rendered on it.
The format of the image is `QImage.Format_ARGB32_Premultiplied`.
The size of the image is the default size ( ceiled to integers )
of the graphic.
:return: The graphic as image in default size
.. py:method:: toImage(size, [aspectRatioMode=Qt.IgnoreAspectRatio])
Convert the graphic to a `QImage`
All pixels of the image get initialized by 0 ( transparent )
before the graphic is scaled and rendered on it.
The format of the image is `QImage.Format_ARGB32_Premultiplied`.
:param QSize size: Size of the image
:param `Qt.AspectRatioMode` aspectRatioMode: Aspect ratio how to scale the graphic
:return: The graphic as image
.. seealso::
:py:meth:`toPixmap()`, :py:meth:`render()`
"""
if len(args) == 0:
if self.isNull():
return QImage()
sz = self.defaultSize()
w = np.ceil(sz.width())
h = np.ceil(sz.height())
image = QImage(w, h, QImage.Format_ARGB32)
image.fill(0)
r = QRect(0, 0, sz.width(), sz.height())
painter = QPainter(image)
self.render(painter, r, Qt.KeepAspectRatio)
painter.end()
return image
elif len(args) in (1, 2):
size = args[0]
aspectRatioMode = Qt.IgnoreAspectRatio
if len(args) == 2:
aspectRatioMode = args[-1]
image = QImage(size, QImage.Format_ARGB32_Premultiplied)
image.fill(0)
r = QRect(0, 0, size.width(), size.height())
painter = QPainter(image)
self.render(painter, r, aspectRatioMode)
return image
示例7: paintEvent
# 需要導入模塊: from qwt.qt.QtGui import QPainter [as 別名]
# 或者: from qwt.qt.QtGui.QPainter import end [as 別名]
def paintEvent(self, event):
painter = QPainter(self)
painter.setClipRegion(event.region())
if self.testPaintAttribute(self.BackingStore) and\
self.__data.backingStore is not None:
bs = self.__data.backingStore
if bs.size() != self.size():
bs = QwtPainter.backingStore(self, self.size())
if self.testAttribute(Qt.WA_StyledBackground):
p = QPainter(bs)
qwtFillBackground(p, self)
self.drawCanvas(p, True)
else:
p = QPainter()
if self.__data.borderRadius <= 0.:
# print('**DEBUG: QwtPlotCanvas.paintEvent')
QwtPainter.fillPixmap(self, bs)
p.begin(bs)
self.drawCanvas(p, False)
else:
p.begin(bs)
qwtFillBackground(p, self)
self.drawCanvas(p, True)
if self.frameWidth() > 0:
self.drawBorder(p)
p.end()
painter.drawPixmap(0, 0, self.__data.backingStore)
else:
if self.testAttribute(Qt.WA_StyledBackground):
if self.testAttribute(Qt.WA_OpaquePaintEvent):
qwtFillBackground(painter, self)
self.drawCanvas(painter, True)
else:
self.drawCanvas(painter, False)
else:
if self.testAttribute(Qt.WA_OpaquePaintEvent):
if self.autoFillBackground():
qwtFillBackground(painter, self)
qwtDrawBackground(painter, self)
else:
if self.borderRadius() > 0.:
clipPath = QPainterPath()
clipPath.addRect(self.rect())
clipPath = clipPath.subtracted(self.borderPath(self.rect()))
painter.save()
painter.setClipPath(clipPath, Qt.IntersectClip)
qwtFillBackground(painter, self)
qwtDrawBackground(painter, self)
painter.restore()
self.drawCanvas(painter, False)
if self.frameWidth() > 0:
self.drawBorder(painter)
if self.hasFocus() and self.focusIndicator() == self.CanvasFocusIndicator:
self.drawFocusIndicator(painter)
示例8: qwtFillBackground
# 需要導入模塊: from qwt.qt.QtGui import QPainter [as 別名]
# 或者: from qwt.qt.QtGui.QPainter import end [as 別名]
def qwtFillBackground(*args):
if len(args) == 2:
painter, canvas = args
rects = []
if canvas.testAttribute(Qt.WA_StyledBackground):
recorder = QwtStyleSheetRecorder(canvas.size())
p = QPainter(recorder)
qwtDrawStyledBackground(canvas, p)
p.end()
if recorder.background.brush.isOpaque():
rects = recorder.clipRects
else:
rects += [canvas.rect()]
else:
r = canvas.rect()
radius = canvas.borderRadius()
if radius > 0.:
sz = QSizeF(radius, radius)
rects += [QRectF(r.topLeft(), sz),
QRectF(r.topRight()-QPointF(radius, 0), sz),
QRectF(r.bottomRight()-QPointF(radius, radius), sz),
QRectF(r.bottomLeft()-QPointF(0, radius), sz)]
qwtFillBackground(painter, canvas, rects)
elif len(args) == 3:
painter, widget, fillRects = args
if not fillRects:
return
if painter.hasClipping():
clipRegion = painter.transform().map(painter.clipRegion())
else:
clipRegion = widget.contentsRect()
bgWidget = qwtBackgroundWidget(widget.parentWidget())
for fillRect in fillRects:
rect = fillRect.toAlignedRect()
if clipRegion.intersects(rect):
pm = QPixmap(rect.size())
QwtPainter.fillPixmap(bgWidget, pm, widget.mapTo(bgWidget, rect.topLeft()))
painter.drawPixmap(rect, pm)
else:
raise TypeError("%s() takes 2 or 3 argument(s) (%s given)"\
% ("qwtFillBackground", len(args)))
示例9: qwtBackgroundWidget
# 需要導入模塊: from qwt.qt.QtGui import QPainter [as 別名]
# 或者: from qwt.qt.QtGui.QPainter import end [as 別名]
def qwtBackgroundWidget(w):
if w.parentWidget() is None:
return w
if w.autoFillBackground():
brush = w.palette().brush(w.backgroundRole())
if brush.color().alpha() > 0:
return w
if w.testAttribute(Qt.WA_StyledBackground):
image = QImage(1, 1, QImage.Format_ARGB32)
image.fill(Qt.transparent)
painter = QPainter(image)
painter.translate(-w.rect().center())
qwtDrawStyledBackground(w, painter)
painter.end()
if qAlpha(image.pixel(0, 0)) != 0:
return w
return qwtBackgroundWidget(w.parentWidget())
示例10: drawColorBar
# 需要導入模塊: from qwt.qt.QtGui import QPainter [as 別名]
# 或者: from qwt.qt.QtGui.QPainter import end [as 別名]
def drawColorBar(self, painter, colorMap, interval, scaleMap,
orientation, rect):
"""
Draw a color bar into a rectangle
:param QPainter painter: Painter
:param qwt.color_map.QwtColorMap colorMap: Color map
:param qwt.interval.QwtInterval interval: Value range
:param qwt.scalemap.QwtScaleMap scaleMap: Scale map
:param Qt.Orientation orientation: Orientation
:param QRectF rect: Target rectangle
"""
colorTable = []
if colorMap.format() == QwtColorMap.Indexed:
colorTable = colorMap.colorTable(interval)
c = QColor()
devRect = rect.toAlignedRect()
pixmap = QPixmap(devRect.size())
pixmap.fill(Qt.transparent)
pmPainter = QPainter(pixmap)
pmPainter.translate(-devRect.x(), -devRect.y())
if orientation == Qt.Horizontal:
sMap = QwtScaleMap(scaleMap)
sMap.setPaintInterval(rect.left(), rect.right())
for x in range(devRect.left(), devRect.right()+1):
value = sMap.invTransform(x)
if colorMap.format() == QwtColorMap.RGB:
c.setRgba(colorMap.rgb(interval, value))
else:
c = colorTable[colorMap.colorIndex(interval, value)]
pmPainter.setPen(c)
pmPainter.drawLine(x, devRect.top(), x, devRect.bottom())
else:
sMap = QwtScaleMap(scaleMap)
sMap.setPaintInterval(rect.bottom(), rect.top())
for y in range(devRect.top(), devRect.bottom()+1):
value = sMap.invTransform(y)
if colorMap.format() == QwtColorMap.RGB:
c.setRgba(colorMap.rgb(interval, value))
else:
c = colorTable[colorMap.colorIndex(interval, value)]
pmPainter.setPen(c)
pmPainter.drawLine(devRect.left(), y, devRect.right(), y)
pmPainter.end()
self.drawPixmap(painter, rect, pixmap)
示例11: updateStyleSheetInfo
# 需要導入模塊: from qwt.qt.QtGui import QPainter [as 別名]
# 或者: from qwt.qt.QtGui.QPainter import end [as 別名]
def updateStyleSheetInfo(self):
if not self.testAttribute(Qt.WA_StyledBackground):
return
recorder = QwtStyleSheetRecorder(self.size())
painter = QPainter(recorder)
opt = QStyleOption()
opt.initFrom(self)
self.style().drawPrimitive(QStyle.PE_Widget, opt, painter, self)
painter.end()
self.__data.styleSheet.hasBorder = not recorder.border.rectList.isEmpty()
self.__data.styleSheet.cornerRects = recorder.clipRects
if recorder.background.path.isEmpty():
if not recorder.border.rectList.isEmpty():
self.__data.styleSheet.borderPath =\
qwtCombinePathList(self.rect(), recorder.border.pathlist)
else:
self.__data.styleSheet.borderPath = recorder.background.path
self.__data.styleSheet.background.brush = recorder.background.brush
self.__data.styleSheet.background.origin = recorder.background.origin
示例12: qwtDrawBackground
# 需要導入模塊: from qwt.qt.QtGui import QPainter [as 別名]
# 或者: from qwt.qt.QtGui.QPainter import end [as 別名]
def qwtDrawBackground(painter, canvas):
painter.save()
borderClip = canvas.borderPath(canvas.rect())
if not borderClip.isEmpty():
painter.setClipPath(borderClip, Qt.IntersectClip)
brush = canvas.palette().brush(canvas.backgroundRole())
if brush.style() == Qt.TexturePattern:
pm = QPixmap(canvas.size())
QwtPainter.fillPixmap(canvas, pm)
painter.drawPixmap(0, 0, pm)
elif brush.gradient():
rects = []
if brush.gradient().coordinateMode() == QGradient.ObjectBoundingMode:
rects += [canvas.rect()]
else:
rects += [painter.clipRegion().rects()]
useRaster = False
if painter.paintEngine().type() == QPaintEngine.X11:
useRaster = True
if useRaster:
format_ = QImage.Format_RGB32
stops = brush.gradient().stops()
for stop in stops:
if stop.second.alpha() != 255:
format_ = QImage.Format_ARGB32
break
image = QImage(canvas.size(), format_)
p = QPainter(image)
p.setPen(Qt.NoPen)
p.setBrush(brush)
p.drawRects(_rects_conv_PyQt5(rects))
p.end()
painter.drawImage(0, 0, image)
else:
painter.setPen(Qt.NoPen)
painter.setBrush(brush)
painter.drawRects(_rects_conv_PyQt5(rects))
else:
painter.setPen(Qt.NoPen)
painter.setBrush(brush)
painter.drawRects(_rects_conv_PyQt5(painter.clipRegion().rects()))
painter.restore()
示例13: toPixmap
# 需要導入模塊: from qwt.qt.QtGui import QPainter [as 別名]
# 或者: from qwt.qt.QtGui.QPainter import end [as 別名]
def toPixmap(self, *args):
"""
Convert the graphic to a `QPixmap`
All pixels of the pixmap get initialized by `Qt.transparent`
before the graphic is scaled and rendered on it.
The size of the pixmap is the default size ( ceiled to integers )
of the graphic.
:return: The graphic as pixmap in default size
.. seealso::
:py:meth:`defaultSize()`, :py:meth:`toImage()`, :py:meth:`render()`
"""
if len(args) == 0:
if self.isNull():
return QPixmap()
sz = self.defaultSize()
w = np.ceil(sz.width())
h = np.ceil(sz.height())
pixmap = QPixmap(w, h)
pixmap.fill(Qt.transparent)
r = QRectF(0., 0., sz.width(), sz.height())
painter = QPainter(pixmap)
self.render(painter, r, Qt.KeepAspectRatio)
painter.end()
return pixmap
elif len(args) in (1, 2):
size = args[0]
aspectRatioMode = Qt.IgnoreAspectRatio
if len(args) == 2:
aspectRatioMode = args[-1]
pixmap = QPixmap(size)
pixmap.fill(Qt.transparent)
r = QRect(0, 0, size.width(), size.height())
painter = QPainter(pixmap)
self.render(painter, r, aspectRatioMode)
painter.end()
return pixmap
示例14: borderPath
# 需要導入模塊: from qwt.qt.QtGui import QPainter [as 別名]
# 或者: from qwt.qt.QtGui.QPainter import end [as 別名]
def borderPath(self, rect):
if self.testAttribute(Qt.WA_StyledBackground):
recorder = QwtStyleSheetRecorder(rect.size())
painter = QPainter(recorder)
opt = QStyleOption()
opt.initFrom(self)
opt.rect = rect
self.style().drawPrimitive(QStyle.PE_Widget, opt, painter, self)
painter.end()
if not recorder.background.path.isEmpty():
return recorder.background.path
if not recorder.border.rectList.isEmpty():
return qwtCombinePathList(rect, recorder.border.pathlist)
elif self.__data.borderRadius > 0.:
fw2 = self.frameWidth()*.5
r = QRectF(rect).adjusted(fw2, fw2, -fw2, -fw2)
path = QPainterPath()
path.addRoundedRect(r, self.__data.borderRadius,
self.__data.borderRadius)
return path
return QPainterPath()
示例15: findAscent
# 需要導入模塊: from qwt.qt.QtGui import QPainter [as 別名]
# 或者: from qwt.qt.QtGui.QPainter import end [as 別名]
def findAscent(self, font):
dummy = "E"
white = QColor(Qt.white)
fm = self.fontmetrics(font)
pm = QPixmap(fm.width(dummy), fm.height())
pm.fill(white)
p = QPainter(pm)
p.setFont(font)
p.drawText(0, 0, pm.width(), pm.height(), 0, dummy)
p.end()
img = pm.toImage()
w = pm.width()
linebytes = w*4
for row in range(img.height()):
line = img.scanLine(row).asstring(linebytes)
for col in range(w):
color = struct.unpack('I', line[col*4:(col+1)*4])[0]
if color != white.rgb():
return fm.ascent()-row+1
return fm.ascent()