Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
QPicture Class Reference

The QPicture class is a paint device that records and replays QPainter commands. More...

#include <qpicture.h>

Inheritance diagram for QPicture:
Collaboration diagram for QPicture:

Public Types

typedef QExplicitlySharedDataPointer< QPicturePrivateDataPtr
Public Types inherited from QPaintDevice
enum  PaintDeviceMetric {
  PdmWidth = 1 , PdmHeight , PdmWidthMM , PdmHeightMM ,
  PdmNumColors , PdmDepth , PdmDpiX , PdmDpiY ,
  PdmPhysicalDpiX , PdmPhysicalDpiY , PdmDevicePixelRatio , PdmDevicePixelRatioScaled ,
  PdmDevicePixelRatioF_EncodedA , PdmDevicePixelRatioF_EncodedB
}

Public Member Functions

 QPicture (int formatVersion=-1)
 Constructs an empty picture.
 QPicture (const QPicture &)
 Constructs a copy of pic.
 ~QPicture ()
 Destroys the picture.
bool isNull () const
 Returns true if the picture contains no data; otherwise returns false.
int devType () const override
uint size () const
 Returns the size of the picture data.
const char * data () const
 Returns a pointer to the picture data.
virtual void setData (const char *data, uint size)
 Sets the picture data directly from data and size.
bool play (QPainter *p)
 Replays the picture using painter, and returns true if successful; otherwise returns false.
bool load (QIODevice *dev)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.dev is the device to use for loading.
bool load (const QString &fileName)
 Loads a picture from the file specified by fileName and returns true if successful; otherwise invalidates the picture and returns false.
bool save (QIODevice *dev)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.dev is the device to use for saving.
bool save (const QString &fileName)
 Saves a picture to the file specified by fileName and returns true if successful; otherwise returns false.
QRect boundingRect () const
 Returns the picture's bounding rectangle or an invalid rectangle if the picture contains no data.
void setBoundingRect (const QRect &r)
 Sets the picture's bounding rectangle to r.
QPictureoperator= (const QPicture &p)
 Move-assigns other to this QPicture instance.
void swap (QPicture &other) noexcept
 \memberswap{picture}
void detach ()
bool isDetached () const
QPaintEnginepaintEngine () const override
DataPtrdata_ptr ()
Public Member Functions inherited from QPaintDevice
virtual ~QPaintDevice ()
bool paintingActive () const
int width () const
int height () const
int widthMM () const
int heightMM () const
int logicalDpiX () const
int logicalDpiY () const
int physicalDpiX () const
int physicalDpiY () const
qreal devicePixelRatio () const
qreal devicePixelRatioF () const
int colorCount () const
int depth () const

Protected Member Functions

 QPicture (QPicturePrivate &data)
int metric (PaintDeviceMetric m) const override
Protected Member Functions inherited from QPaintDevice
 QPaintDevice () noexcept
virtual void initPainter (QPainter *painter) const
virtual QPaintDeviceredirected (QPoint *offset) const
virtual QPaintersharedPainter () const
double getDecodedMetricF (PaintDeviceMetric metricA, PaintDeviceMetric metricB) const

Friends

class QPicturePaintEngine
class QAlphaPaintEngine
class QPreviewPaintEngine
Q_GUI_EXPORT QDataStreamoperator<< (QDataStream &in, const QPicture &p)
 Writes picture r to the stream s and returns a reference to the stream.
Q_GUI_EXPORT QDataStreamoperator>> (QDataStream &in, QPicture &p)
 Reads a picture from the stream s into picture r and returns a reference to the stream.

Additional Inherited Members

Static Public Member Functions inherited from QPaintDevice
static qreal devicePixelRatioFScale ()
static int encodeMetricF (PaintDeviceMetric metric, double value)
Protected Attributes inherited from QPaintDevice
ushort painters

Detailed Description

The QPicture class is a paint device that records and replays QPainter commands.

\inmodule QtGui

A picture serializes painter commands to an IO device in a platform-independent format. They are sometimes referred to as meta-files.

Qt pictures use a proprietary binary format. Unlike native picture (meta-file) formats on many window systems, Qt pictures have no limitations regarding their contents. Everything that can be painted on a widget or pixmap (e.g., fonts, pixmaps, regions, transformed graphics, etc.) can also be stored in a picture.

QPicture is resolution independent, i.e. a QPicture can be displayed on different devices (for example svg, pdf, ps, printer and screen) looking the same. This is, for instance, needed for WYSIWYG print preview. QPicture runs in the default system dpi, and scales the painter to match differences in resolution depending on the window system.

Example of how to record a picture:

QPicture picture;
QPainter painter;
painter.begin(&picture); // paint in picture
painter.drawEllipse(10,20, 80,70); // draw an ellipse
painter.end(); // painting done
picture.save("drawing.pic"); // save picture

Note that the list of painter commands is reset on each call to the QPainter::begin() function.

Example of how to replay a picture:

QPicture picture;
picture.load("drawing.pic"); // load picture
QPainter painter;
painter.begin(&myImage); // paint in myImage
painter.drawPicture(0, 0, picture); // draw the picture at (0,0)
painter.end(); // painting done

Pictures can also be drawn using play(). Some basic data about a picture is available, for example, size(), isNull() and boundingRect().

Note
QPicture uses QDataStream for serialization. The \l {QDataStream#Corruption and Security}{same reservations} against reading untrusted data apply.
See also
QMovie

Definition at line 18 of file qpicture.h.

Member Typedef Documentation

◆ DataPtr

Constructor & Destructor Documentation

◆ QPicture() [1/3]

QPicture::QPicture ( int formatVersion = -1)
explicit

Constructs an empty picture.

The formatVersion parameter may be used to create a QPicture that can be read by applications that are compiled with earlier versions of Qt.

Note that the default formatVersion is -1 which signifies the current release, i.e. for Qt 4.0 a formatVersion of 7 is the same as the default formatVersion of -1.

Reading pictures generated by earlier versions of Qt is not supported in Qt 4.0.

Definition at line 113 of file qpicture.cpp.

◆ QPicture() [2/3]

QPicture::QPicture ( const QPicture & pic)

Constructs a copy of pic.

This constructor is fast thanks to \l{implicit sharing}.

Definition at line 138 of file qpicture.cpp.

◆ ~QPicture()

QPicture::~QPicture ( )

Destroys the picture.

Definition at line 153 of file qpicture.cpp.

◆ QPicture() [3/3]

QPicture::QPicture ( QPicturePrivate & dptr)
protected

Definition at line 144 of file qpicture.cpp.

Member Function Documentation

◆ boundingRect()

QRect QPicture::boundingRect ( ) const

Returns the picture's bounding rectangle or an invalid rectangle if the picture contains no data.

Definition at line 307 of file qpicture.cpp.

◆ data()

const char * QPicture::data ( ) const

Returns a pointer to the picture data.

The pointer is only valid until the next non-const function is called on this picture. The returned pointer is 0 if the picture contains no data.

See also
size(), isNull()

Definition at line 201 of file qpicture.cpp.

◆ data_ptr()

DataPtr & QPicture::data_ptr ( )
inline

Definition at line 70 of file qpicture.h.

◆ detach()

void QPicture::detach ( )

Detaches from shared picture data and makes sure that this picture is the only one referring to the data.

If multiple pictures share common data, this picture makes a copy of the data and detaches itself from the sharing mechanism. Nothing is done if there is just a single reference.

Definition at line 206 of file qpicture.cpp.

◆ devType()

int QPicture::devType ( ) const
overridevirtual

Reimplemented from QPaintDevice.

Definition at line 160 of file qpicture.cpp.

◆ isDetached()

bool QPicture::isDetached ( ) const

Definition at line 211 of file qpicture.cpp.

◆ isNull()

bool QPicture::isNull ( ) const

Returns true if the picture contains no data; otherwise returns false.

Definition at line 191 of file qpicture.cpp.

◆ load() [1/2]

bool QPicture::load ( const QString & fileName)

Loads a picture from the file specified by fileName and returns true if successful; otherwise invalidates the picture and returns false.

See also
save()

Definition at line 238 of file qpicture.cpp.

◆ load() [2/2]

bool QPicture::load ( QIODevice * dev)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.dev is the device to use for loading.

Definition at line 254 of file qpicture.cpp.

◆ metric()

int QPicture::metric ( PaintDeviceMetric m) const
overrideprotectedvirtual

Internal implementation of the virtual QPaintDevice::metric() function.

A picture has the following hard-coded values: numcolors=16777216 and depth=24.

m is the metric to get.

Reimplemented from QPaintDevice.

Definition at line 893 of file qpicture.cpp.

◆ operator=()

QPicture & QPicture::operator= ( const QPicture & p)

Move-assigns other to this QPicture instance.

Assigns picture p to this picture and returns a reference to this picture.

Since
5.2

Definition at line 956 of file qpicture.cpp.

◆ paintEngine()

QPaintEngine * QPicture::paintEngine ( ) const
overridevirtual

Implements QPaintDevice.

Definition at line 1085 of file qpicture.cpp.

◆ play()

bool QPicture::play ( QPainter * painter)

Replays the picture using painter, and returns true if successful; otherwise returns false.

This function does exactly the same as QPainter::drawPicture() with (x, y) = (0, 0).

Note
The state of the painter isn't preserved by this function.

Definition at line 340 of file qpicture.cpp.

◆ save() [1/2]

bool QPicture::save ( const QString & fileName)

Saves a picture to the file specified by fileName and returns true if successful; otherwise returns false.

See also
load()

Definition at line 270 of file qpicture.cpp.

◆ save() [2/2]

bool QPicture::save ( QIODevice * dev)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.dev is the device to use for saving.

Definition at line 290 of file qpicture.cpp.

◆ setBoundingRect()

void QPicture::setBoundingRect ( const QRect & r)

Sets the picture's bounding rectangle to r.

The automatically calculated value is overridden.

Definition at line 325 of file qpicture.cpp.

◆ setData()

void QPicture::setData ( const char * data,
uint size )
virtual

Sets the picture data directly from data and size.

This function copies the input data.

See also
data(), size()

Definition at line 223 of file qpicture.cpp.

◆ size()

uint QPicture::size ( ) const

Returns the size of the picture data.

See also
data()

Definition at line 196 of file qpicture.cpp.

◆ swap()

void QPicture::swap ( QPicture & other)
inlinenoexcept

\memberswap{picture}

Definition at line 45 of file qpicture.h.

◆ operator<<

QDataStream & operator<< ( QDataStream & in,
const QPicture & p )
friend

Writes picture r to the stream s and returns a reference to the stream.

Definition at line 1104 of file qpicture.cpp.

◆ operator>>

QDataStream & operator>> ( QDataStream & in,
QPicture & p )
friend

Reads a picture from the stream s into picture r and returns a reference to the stream.

Definition at line 1123 of file qpicture.cpp.

◆ QAlphaPaintEngine

friend class QAlphaPaintEngine
friend

Definition at line 65 of file qpicture.h.

◆ QPicturePaintEngine

friend class QPicturePaintEngine
friend

Definition at line 64 of file qpicture.h.

◆ QPreviewPaintEngine

friend class QPreviewPaintEngine
friend

Definition at line 66 of file qpicture.h.


The documentation for this class was generated from the following files: