![]() |
Qt 6.x
The Qt SDK
|
The QPicture class is a paint device that records and replays QPainter commands. More...
#include <qpicture.h>
Public Types | |
typedef QExplicitlySharedDataPointer< QPicturePrivate > | DataPtr |
![]() | |
enum | PaintDeviceMetric { PdmWidth = 1 , PdmHeight , PdmWidthMM , PdmHeightMM , PdmNumColors , PdmDepth , PdmDpiX , PdmDpiY , PdmPhysicalDpiX , PdmPhysicalDpiY , PdmDevicePixelRatio , PdmDevicePixelRatioScaled } |
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. | |
QPicture & | operator= (const QPicture &p) |
Move-assigns other to this QPicture instance. | |
void | swap (QPicture &other) noexcept |
void | detach () |
bool | isDetached () const |
QPaintEngine * | paintEngine () const override |
DataPtr & | data_ptr () |
![]() | |
virtual | ~QPaintDevice () |
virtual int | devType () const |
bool | paintingActive () const |
virtual QPaintEngine * | paintEngine () const =0 |
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 |
![]() | |
QPaintDevice () noexcept | |
virtual int | metric (PaintDeviceMetric metric) const |
virtual void | initPainter (QPainter *painter) const |
virtual QPaintDevice * | redirected (QPoint *offset) const |
virtual QPainter * | sharedPainter () const |
Friends | |
class | QPicturePaintEngine |
class | QAlphaPaintEngine |
class | QPreviewPaintEngine |
Q_GUI_EXPORT QDataStream & | operator<< (QDataStream &in, const QPicture &p) |
Writes picture r to the stream s and returns a reference to the stream. | |
Q_GUI_EXPORT QDataStream & | operator>> (QDataStream &in, QPicture &p) |
Reads a picture from the stream s into picture r and returns a reference to the stream. | |
Related Symbols | |
(Note that these are not member symbols.) | |
QDataStream & | operator<< (QDataStream &s, const QPicture &r) |
Writes picture r to the stream s and returns a reference to the stream. | |
QDataStream & | operator>> (QDataStream &s, QPicture &r) |
Reads a picture from the stream s into picture r and returns a reference to the stream. | |
Additional Inherited Members | |
![]() | |
static qreal | devicePixelRatioFScale () |
![]() | |
ushort | painters |
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:
Note that the list of painter commands is reset on each call to the QPainter::begin() function.
Example of how to replay a picture:
Pictures can also be drawn using play(). Some basic data about a picture is available, for example, size(), isNull() and boundingRect().
Definition at line 18 of file qpicture.h.
Definition at line 69 of file qpicture.h.
|
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 102 of file qpicture.cpp.
QPicture::QPicture | ( | const QPicture & | pic | ) |
Constructs a copy of pic.
This constructor is fast thanks to \l{implicit sharing}.
Definition at line 127 of file qpicture.cpp.
QPicture::~QPicture | ( | ) |
Destroys the picture.
Definition at line 142 of file qpicture.cpp.
|
protected |
Definition at line 133 of file qpicture.cpp.
QRect QPicture::boundingRect | ( | ) | const |
Returns the picture's bounding rectangle or an invalid rectangle if the picture contains no data.
Definition at line 296 of file qpicture.cpp.
References QPicturePrivate::checkFormat(), and d.
Referenced by QPicturePaintEngine::begin(), and metric().
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.
Definition at line 190 of file qpicture.cpp.
|
inline |
Definition at line 70 of file qpicture.h.
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 195 of file qpicture.cpp.
References QExplicitlySharedDataPointer< T >::detach().
Referenced by load(), and setData().
|
overridevirtual |
Reimplemented from QPaintDevice.
Definition at line 149 of file qpicture.cpp.
References QInternal::Picture.
bool QPicture::isDetached | ( | ) | const |
Definition at line 200 of file qpicture.cpp.
bool QPicture::isNull | ( | ) | const |
Returns true
if the picture contains no data; otherwise returns false.
Definition at line 180 of file qpicture.cpp.
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
.
Definition at line 227 of file qpicture.cpp.
References fileName, load(), operator=(), and QIODeviceBase::ReadOnly.
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 243 of file qpicture.cpp.
References detach(), and QIODevice::readAll().
Referenced by load().
|
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 857 of file qpicture.cpp.
References boundingRect(), QPaintDevice::devicePixelRatioFScale(), QRect::height(), QPaintDevice::PdmDepth, QPaintDevice::PdmDevicePixelRatio, QPaintDevice::PdmDevicePixelRatioScaled, QPaintDevice::PdmDpiX, QPaintDevice::PdmDpiY, QPaintDevice::PdmHeight, QPaintDevice::PdmHeightMM, QPaintDevice::PdmNumColors, QPaintDevice::PdmPhysicalDpiX, QPaintDevice::PdmPhysicalDpiY, QPaintDevice::PdmWidth, QPaintDevice::PdmWidthMM, qt_defaultDpiX(), qt_defaultDpiY(), qWarning, and QRect::width().
Move-assigns other to this QPicture instance.
Assigns picture p to this picture and returns a reference to this picture.
Definition at line 920 of file qpicture.cpp.
Referenced by load().
|
overridevirtual |
Implements QPaintDevice.
Definition at line 1052 of file qpicture.cpp.
References paintEngine().
Referenced by paintEngine().
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).
Definition at line 329 of file qpicture.cpp.
References d, exec(), painter, QPicturePrivate::PdcBegin, Q_ASSERT, qWarning, and QIODeviceBase::ReadOnly.
bool QPicture::save | ( | const QString & | fileName | ) |
Saves a picture to the file specified by fileName and returns true if successful; otherwise returns false
.
Definition at line 259 of file qpicture.cpp.
References fileName, QPaintDevice::paintingActive(), qWarning, save(), and QIODeviceBase::WriteOnly.
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 279 of file qpicture.cpp.
References QPaintDevice::paintingActive(), qWarning, and QIODevice::write().
Referenced by save().
Sets the picture's bounding rectangle to r.
The automatically calculated value is overridden.
Definition at line 314 of file qpicture.cpp.
Sets the picture data directly from data and size.
This function copies the input data.
Definition at line 212 of file qpicture.cpp.
References detach().
uint QPicture::size | ( | ) | const |
Swaps picture other with this picture. This operation is very fast and never fails.
Definition at line 45 of file qpicture.h.
References other().
|
friend |
Writes picture r to the stream s and returns a reference to the stream.
Definition at line 1071 of file qpicture.cpp.
|
related |
Writes picture r to the stream s and returns a reference to the stream.
Definition at line 1071 of file qpicture.cpp.
|
friend |
Reads a picture from the stream s into picture r and returns a reference to the stream.
Definition at line 1090 of file qpicture.cpp.
|
related |
Reads a picture from the stream s into picture r and returns a reference to the stream.
Definition at line 1090 of file qpicture.cpp.
|
friend |
Definition at line 65 of file qpicture.h.
|
friend |
Definition at line 64 of file qpicture.h.
|
friend |
Definition at line 66 of file qpicture.h.