QwtSymbol¶
- class qwt.symbol.QwtSymbol(*args)[source]¶
A class for drawing symbols
Symbol styles:
QwtSymbol.NoSymbol: No Style. The symbol cannot be drawn.
QwtSymbol.Ellipse: Ellipse or circle
QwtSymbol.Rect: Rectangle
QwtSymbol.Diamond: Diamond
QwtSymbol.Triangle: Triangle pointing upwards
QwtSymbol.DTriangle: Triangle pointing downwards
QwtSymbol.UTriangle: Triangle pointing upwards
QwtSymbol.LTriangle: Triangle pointing left
QwtSymbol.RTriangle: Triangle pointing right
QwtSymbol.Cross: Cross (+)
QwtSymbol.XCross: Diagonal cross (X)
QwtSymbol.HLine: Horizontal line
QwtSymbol.VLine: Vertical line
QwtSymbol.Star1: X combined with +
QwtSymbol.Star2: Six-pointed star
QwtSymbol.Hexagon: Hexagon
QwtSymbol.Path: The symbol is represented by a painter path, where the origin (0, 0) of the path coordinate system is mapped to the position of the symbol
..seealso:
:py:meth:`setPath()`, :py:meth:`path()`
QwtSymbol.Pixmap: The symbol is represented by a pixmap. The pixmap is centered or aligned to its pin point.
..seealso:
:py:meth:`setPinPoint()`
QwtSymbol.Graphic: The symbol is represented by a graphic. The graphic is centered or aligned to its pin point.
..seealso:
:py:meth:`setPinPoint()`
QwtSymbol.SvgDocument: The symbol is represented by a SVG graphic. The graphic is centered or aligned to its pin point.
..seealso:
:py:meth:`setPinPoint()`
QwtSymbol.UserStyle: Styles >= QwtSymbol.UserStyle are reserved for derived classes of QwtSymbol that overload drawSymbols() with additional application specific symbol types.
Cache policies:
Depending on the render engine and the complexity of the symbol shape it might be faster to render the symbol to a pixmap and to paint this pixmap.
F.e. the raster paint engine is a pure software renderer where in cache mode a draw operation usually ends in raster operation with the the backing store, that are usually faster, than the algorithms for rendering polygons. But the opposite can be expected for graphic pipelines that can make use of hardware acceleration.
The default setting is AutoCache
..seealso:
:py:meth:`setCachePolicy()`, :py:meth:`cachePolicy()`
Note
The policy has no effect, when the symbol is painted to a vector graphics format (PDF, SVG).
Warning
Since Qt 4.8 raster is the default backend on X11
Valid cache policies:
QwtSymbol.NoCache: Don’t use a pixmap cache
QwtSymbol.Cache: Always use a pixmap cache
QwtSymbol.AutoCache: Use a cache when the symbol is rendered with the software renderer (QPaintEngine.Raster)
- class QwtSymbol([style=QwtSymbol.NoSymbol])¶
The symbol is constructed with gray interior, black outline with zero width, no size and style ‘NoSymbol’.
- Parameters:
style (int) – Symbol Style
- class QwtSymbol(style, brush, pen, size)
- Parameters:
style (int) – Symbol Style
brush (QBrush) – Brush to fill the interior
pen (QPen) – Outline pen
size (QSize) – Size
- class QwtSymbol(path, brush, pen)
- Parameters:
path (QPainterPath) – Painter path
brush (QBrush) – Brush to fill the interior
pen (QPen) – Outline pen
See also
- Style¶
alias of
int
- classmethod make(style=None, brush=None, pen=None, size=None, path=None, pixmap=None, graphic=None, svgdocument=None, pinpoint=None)[source]¶
Create and setup a new QwtSymbol object (convenience function).
- Parameters:
style (int or None) – Symbol Style
brush (QBrush or None) – Brush to fill the interior
pen (QPen or None) – Outline pen
size (QSize or None) – Size
path (QPainterPath or None) – Painter path
path – Painter path
pixmap (QPixmap or None) – Pixmap as symbol
graphic (qwt.graphic.QwtGraphic or None) – Graphic
svgdocument – SVG icon as symbol
See also
- setCachePolicy(policy)[source]¶
Change the cache policy
The default policy is AutoCache
- Parameters:
policy (int) – Cache policy
See also
- setPath(path)[source]¶
Set a painter path as symbol
The symbol is represented by a painter path, where the origin (0, 0) of the path coordinate system is mapped to the position of the symbol.
When the symbol has valid size the painter path gets scaled to fit into the size. Otherwise the symbol size depends on the bounding rectangle of the path.
The following code defines a symbol drawing an arrow:
from qtpy.QtGui import QApplication, QPen, QPainterPath, QTransform from qtpy.QtCore import Qt, QPointF from qwt import QwtPlot, QwtPlotCurve, QwtSymbol import numpy as np app = QApplication([]) # --- Construct custom symbol --- path = QPainterPath() path.moveTo(0, 8) path.lineTo(0, 5) path.lineTo(-3, 5) path.lineTo(0, 0) path.lineTo(3, 5) path.lineTo(0, 5) transform = QTransform() transform.rotate(-30.0) path = transform.map(path) pen = QPen(Qt.black, 2 ); pen.setJoinStyle(Qt.MiterJoin) symbol = QwtSymbol() symbol.setPen(pen) symbol.setBrush(Qt.red) symbol.setPath(path) symbol.setPinPoint(QPointF(0., 0.)) symbol.setSize(10, 14) # --- Test it within a simple plot --- curve = QwtPlotCurve() curve_pen = QPen(Qt.blue) curve_pen.setStyle(Qt.DotLine) curve.setPen(curve_pen) curve.setSymbol(symbol) x = np.linspace(0, 10, 10) curve.setData(x, np.sin(x)) plot = QwtPlot() curve.attach(plot) plot.resize(600, 300) plot.replot() plot.show() app.exec_()
- Parameters:
path (QPainterPath) – Painter path
- setPixmap(pixmap)[source]¶
Set a pixmap as symbol
- Parameters:
pixmap (QPixmap) – Pixmap
See also
Note
The style() is set to QwtSymbol.Pixmap
Note
brush() and pen() have no effect
- setGraphic(graphic)[source]¶
Set a graphic as symbol
- Parameters:
graphic (qwt.graphic.QwtGraphic) – Graphic
See also
Note
The style() is set to QwtSymbol.Graphic
Note
brush() and pen() have no effect
- setSvgDocument(svgDocument)[source]¶
Set a SVG icon as symbol
- Parameters:
svgDocument – SVG icon
See also
Note
The style() is set to QwtSymbol.SvgDocument
Note
brush() and pen() have no effect
- setSize(*args)[source]¶
Specify the symbol’s size
- setSize(width[, height=-1])[source]
- Parameters:
width (int) – Width
height (int) – Height
- setSize(size)[source]
- Parameters:
size (QSize) – Size
See also
- setBrush(brush)[source]¶
Assign a brush
The brush is used to draw the interior of the symbol.
- Parameters:
brush (QBrush) – Brush
See also
- setPen(*args)[source]¶
Build and/or assign a pen, depending on the arguments.
- setPen(color, width, style)[source]
Build and assign a pen
In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it non cosmetic (see QPen.isCosmetic()). This method signature has been introduced to hide this incompatibility.
- Parameters:
color (QColor) – Pen color
width (float) – Pen width
style (Qt.PenStyle) – Pen style
- setPen(pen)[source]
Assign a pen
- Parameters:
pen (QPen) – New pen
- setColor(color)[source]¶
Set the color of the symbol
Change the color of the brush for symbol types with a filled area. For all other symbol types the color will be assigned to the pen.
- Parameters:
color (QColor) – Color
See also
- setPinPoint(pos, enable=True)[source]¶
Set and enable a pin point
The position of a complex symbol is not always aligned to its center ( f.e an arrow, where the peak points to a position ). The pin point defines the position inside of a Pixmap, Graphic, SvgDocument or PainterPath symbol where the represented point has to be aligned to.
- Parameters:
pos (QPointF) – Position
- Enable bool enable:
En/Disable the pin point alignment
See also
- setPinPointEnabled(on)[source]¶
En/Disable the pin point alignment
- Parameters:
on (bool) – Enabled, when on is true
See also
- drawSymbols(painter, points)[source]¶
Render an array of symbols
Painting several symbols is more effective than drawing symbols one by one, as a couple of layout calculations and setting of pen/brush can be done once for the complete array.
- Parameters:
painter (QPainter) – Painter
points (QPolygonF) – Positions of the symbols in screen coordinates
- drawSymbol(painter, point_or_rect)[source]¶
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.
- Parameters:
painter (QPainter) – Painter
point_or_rect (QPointF or QPoint or QRectF) – Position or target rectangle of the symbol in screen coordinates
- renderSymbols(painter, points)[source]¶
Render the symbol to series of points
- Parameters:
painter (QPainter) – Painter
point_or_rect – Positions of the symbols
- boundingRect()[source]¶
Calculate the bounding rectangle for a symbol at position (0,0).
- Returns:
Bounding rectangle
- invalidateCache()[source]¶
Invalidate the cached symbol pixmap
The symbol invalidates its cache, whenever an attribute is changed that has an effect ob how to display a symbol. In case of derived classes with individual styles (>= QwtSymbol.UserStyle) it might be necessary to call invalidateCache() for attributes that are relevant for this style.
See also