QPicture 类

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

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

公共函数

QPicture (int formatVersion = -1)
QPicture (const QPicture & pic )
virtual ~QPicture ()
QRect boundingRect () const
const char * data () const
bool isNull () const
bool load (const QString & fileName , const char * format = nullptr)
bool load (QIODevice * dev , const char * format = nullptr)
bool play (QPainter * painter )
bool save (const QString & fileName , const char * format = nullptr)
bool save (QIODevice * dev , const char * format = 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 )

额外继承成员

详细描述

The 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)

构造空图片。

The formatVersion 参数可以用于 create a QPicture that can be read by applications that are compiled with earlier versions of Qt.

注意,formatVersion 默认 -1 表示当前发行 (即:对于 Qt 4.0), formatVersion 为 7 如同 formatVersion 默认 -1。

Qt 4.0 不支持读取由早期 Qt 版本生成的图片。

QPicture:: QPicture (const QPicture & pic )

构造副本为 pic .

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

[virtual] QPicture:: ~QPicture ()

销毁图片。

QRect QPicture:: boundingRect () const

返回图片的边界矩形,或无效矩形若图片不包含数据。

另请参阅 setBoundingRect ().

const char *QPicture:: data () const

返回图片数据指针。指针才有效,直到此图片调用下一非 const 函数。返回指针为 0,若图片不包含数据。

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

bool QPicture:: isNull () const

返回 true 若图片不包含数据;否则返回 false。

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

加载图片从文件指定通过 fileName 并返回 true 若成功;否则为无效图片并返回 false .

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

另请参阅 save ().

bool QPicture:: load ( QIODevice * dev , const char * format = 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 = nullptr)

将图片保存到文件指定通过 fileName 并返回 true 若成功;否则返回 false .

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

另请参阅 load ().

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

这是重载函数。

dev 是用于保存的设备。

void QPicture:: setBoundingRect (const QRect & r )

将图片边界矩形设为 r 。覆写自动计算值。

另请参阅 boundingRect ().

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

直接设置图片数据从 data and size 。此函数拷贝输入数据。

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

uint QPicture:: size () const

返回图片数据的大小。

另请参阅 data ().

void QPicture:: swap ( QPicture & other )

交换图片 other 与此图片。此操作非常快且从不失败。

该函数在 Qt 4.8 引入。

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

赋值图片 p 到此图片并返回对此图片的引用。

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 )

读取图片从流 s 到图片 r 并返回流引用。