QPicture 类

QPicture 类是描绘设备,它记录并重演 QPainter 命令。 更多...

头: #include <QPicture>
qmake: QT += gui
继承: QPaintDevice

公共函数

QPicture (int formatVersion = -1)
QPicture (const QPicture & pic )
~QPicture ()
QRect boundingRect () const
const char * data () const
bool isNull () const
bool load (const QString & fileName , const char * format = Q_NULLPTR)
bool load (QIODevice * dev , const char * format = Q_NULLPTR)
bool play (QPainter * painter )
bool save (const QString & fileName , const char * format = Q_NULLPTR)
bool save (QIODevice * dev , const char * format = Q_NULLPTR)
void setBoundingRect (const QRect & r )
virtual void setData (const char * data , uint size )
uint size () const
void swap (QPicture & other )
QPicture & operator= (const QPicture & p )
QPicture & operator= (QPicture && other )
QDataStream & operator<< (QDataStream & s , const QPicture & r )
QDataStream & operator>> (QDataStream & s , QPicture & r )

额外继承成员

详细描述

QPicture 类是描绘设备,它记录并重演 QPainter 命令。

图片以独立于平台的格式将描绘器命令序列化到 IO 设备。它们有时被称为元文件。

QPicture 使用专有二进制格式。不像很多窗口系统中的本机图片 (元文件) 格式,QPicture 在其内容方面没有局限性。可以在 Widget 或像素图中绘制一切 (如:字体、像素图、区域、变换图形、等),也可以存储在图片中。

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.

如何录制图片的范例:

        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
					

注意,描绘器命令列表会被重置当每次调用 QPainter::begin () 函数。

如何重演图片的范例:

        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
					

也可以绘制图片使用 play ()。关于图片的一些基本数据是可用的,例如, size (), isNull () 和 boundingRect ().

另请参阅 QMovie .

成员函数文档编制

QPicture:: QPicture ( int formatVersion = -1)

构造空图片。

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.

QPicture:: QPicture (const QPicture & pic )

构造副本为 pic .

此构造函数很快感谢 隐式共享 .

QPicture:: ~QPicture ()

销毁图片。

QRect QPicture:: boundingRect () const

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

另请参阅 setBoundingRect ().

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.

另请参阅 setData (), size (),和 isNull ().

bool QPicture:: isNull () const

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

bool QPicture:: load (const QString & fileName , const char * format = Q_NULLPTR)

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

Please note that the format parameter has been deprecated and will have no effect.

另请参阅 save ().

bool QPicture:: load ( QIODevice * dev , const char * format = Q_NULLPTR)

这是重载函数。

dev 是用于加载的设备。

bool QPicture:: play ( QPainter * painter )

重演图片使用 painter ,并返回 true 若成功;否则返回 false .

此函数做的准确如同 QPainter::drawPicture () 采用 (x, y) = (0, 0)。

bool QPicture:: save (const QString & fileName , const char * format = Q_NULLPTR)

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

Please note that the format parameter has been deprecated and will have no effect.

另请参阅 load ().

bool QPicture:: save ( QIODevice * dev , const char * format = Q_NULLPTR)

这是重载函数。

dev 是用于保存的设备。

void QPicture:: setBoundingRect (const QRect & r )

Sets the picture's bounding rectangle to r . The automatically calculated value is overridden.

另请参阅 boundingRect ().

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

Sets the picture data directly from data and size . This function copies the input data.

另请参阅 data () 和 size ().

uint QPicture:: size () const

返回图片数据的大小。

另请参阅 data ().

void QPicture:: swap ( QPicture & other )

Swaps picture other with this picture. This operation is very fast and never fails.

该函数在 Qt 4.8 引入。

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

赋值图片 p to this picture and returns a reference to this picture.

QPicture &QPicture:: operator= ( QPicture && other )

移动赋值 other 到此 QPicture 实例。

该函数在 Qt 5.2 引入。

相关非成员

QDataStream & operator<< ( QDataStream & s , const QPicture & r )

写入图片 r 到流 s 并返回流引用。

QDataStream & operator>> ( QDataStream & s , QPicture & r )

Reads a picture from the stream s into picture r 并返回流引用。