QwtGraphic — PythonQwt 0.14 Manual (original) (raw)

class qwt.graphic.QwtGraphic(*args)[source]

A paint device for scalable graphics

QwtGraphic is the representation of a graphic that is tailored for scalability. Like QPicture it will be initialized by QPainteroperations and can be replayed later to any target paint device.

While the usual image representations QImage and QPixmap are not scalable Qt offers two paint devices, that might be candidates for representing a vector graphic:

QwtGraphic maps all scalable drawing primitives to a QPainterPathand stores them together with the painter state changes ( pen, brush, transformation … ) in a list of QwtPaintCommands. For being a complete QPaintDevice it also stores pixmaps or images, what is somehow against the idea of the class, because these objects can’t be scaled without a loss in quality.

The main issue about scaling a QwtGraphic object are the pens used for drawing the outlines of the painter paths. While non cosmetic pens ( QPen.isCosmetic() ) are scaled with the same ratio as the path, cosmetic pens have a fixed width. A graphic might have paths with different pens - cosmetic and non-cosmetic.

QwtGraphic caches 2 different rectangles:

Because the offset for drawing the outline depends on the shape of the painter path ( the peak of a triangle is different than the flat side ) scaling with a fixed aspect ratio always needs to be calculated from the control point rectangle.

class QwtGraphic

Initializes a null graphic

class QwtGraphic(other)

Copy constructor

Parameters:

other (qwt.graphic.QwtGraphic) – Source

reset()[source]

Clear all stored commands

isNull()[source]

Return True, when no painter commands have been stored

isEmpty()[source]

Return True, when the bounding rectangle is empty

setRenderHint(hint, on=True)[source]

Toggle an render hint

testRenderHint(hint)[source]

Test a render hint

boundingRect()[source]

The bounding rectangle is the controlPointRect()extended by the areas needed for rendering the outlines with unscaled pens.

Returns:

Bounding rectangle of the graphic

controlPointRect()[source]

The control point rectangle is the bounding rectangle of all control points of the paths and the target rectangles of the images/pixmaps.

Returns:

Control point rectangle

scaledBoundingRect(sx, sy)[source]

Calculate the target rectangle for scaling the graphic

Parameters:

Returns:

Scaled bounding rectangle

Note

In case of paths that are painted with a cosmetic pen (see QPen.isCosmetic()) the target rectangle is different to multiplying the bounding rectangle.

sizeMetrics()[source]

Return Ceiled defaultSize()

setDefaultSize(size)[source]

The default size is used in all methods rendering the graphic, where no size is explicitly specified. Assigning an empty size means, that the default size will be calculated from the bounding rectangle.

Parameters:

size (QSizeF) – Default size

defaultSize()[source]

When a non empty size has been assigned by setDefaultSize() this size will be returned. Otherwise the default size is the size of the bounding rectangle.

The default size is used in all methods rendering the graphic, where no size is explicitly specified.

Returns:

Default size

render(*args)[source]

render(painter)[source]

Replay all recorded painter commands

Parameters:

painter (QPainter) – Qt painter

render(painter, size, aspectRatioMode)[source]

Replay all recorded painter commands

The graphic is scaled to fit into the rectangle of the given size starting at ( 0, 0 ).

Parameters:

render(painter, rect, aspectRatioMode)[source]

Replay all recorded painter commands

The graphic is scaled to fit into the given rectangle

Parameters:

render(painter, pos, aspectRatioMode)[source]

Replay all recorded painter commands

The graphic is scaled to the defaultSize() and aligned to a position.

Parameters:

toPixmap(*args)[source]

Convert the graphic to a QPixmap

All pixels of the pixmap get initialized by Qt.transparentbefore the graphic is scaled and rendered on it.

The size of the pixmap is the default size ( ceiled to integers ) of the graphic.

Returns:

The graphic as pixmap in default size

toImage(*args)[source]

toImage()[source]

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.

Returns:

The graphic as image in default size

toImage(_size_[, _aspectRatioMode=Qt.IgnoreAspectRatio_])[source]

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.

Parameters:

Returns:

The graphic as image

See also

toPixmap(), render()

drawPath(path)[source]

Store a path command in the command list

Parameters:

path (QPainterPath) – Painter path

See also

QPaintEngine.drawPath()

drawPixmap(rect, pixmap, subRect)[source]

Store a pixmap command in the command list

Parameters:

See also

QPaintEngine.drawPixmap()

drawImage(rect, image, subRect, flags)[source]

Store a image command in the command list

Parameters:

See also

QPaintEngine.drawImage()

updateState(state)[source]

Store a state command in the command list

Parameters:

state (QPaintEngineState) – State to be stored

See also

QPaintEngine.updateState()