QPicture 类

QPicture 类是描绘设备,用于记录和重演 QPainter 命令。 更多...

头: #include <QPicture>
CMake: find_package(Qt6 REQUIRED COMPONENTS Gui)
target_link_libraries(mytarget PRIVATE Qt6::Gui)
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 )
bool load (QIODevice * dev )
bool play (QPainter * painter )
bool save (const QString & fileName )
bool save (QIODevice * dev )
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 )

详细描述

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

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

QPicture 独立于分辨率,即 QPicture 显示在不同设备中 (例如 SVG、PDF、PS、打印机及屏幕) 看起来相同。例如,这是 WYSIWYG (所见即所得) 打印预览需要的。QPicture 按系统默认 DPI (每英寸点数) 运行,且比例缩放描绘器能匹配从属窗口系统的分辨率差异。

如何录制图片的范例:

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 .

成员函数文档编制

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

构造空图片。

The formatVersion 参数可以用于 create QPicture,其可以由采用早期 Qt 版本编译的应用程序所读取。

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

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

QPicture:: QPicture (const QPicture & pic )

构造副本为 pic .

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

[virtual noexcept] 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 )

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

另请参阅 save ().

bool QPicture:: load ( QIODevice * dev )

这是重载函数。

dev 是用于加载的设备。

bool QPicture:: play ( QPainter * painter )

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

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

注意: 此函数未保留描绘器的状态。

bool QPicture:: save (const QString & fileName )

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

另请参阅 load ().

bool QPicture:: save ( QIODevice * dev )

这是重载函数。

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 ().

[noexcept] void QPicture:: swap ( QPicture & other )

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

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

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

[noexcept] QPicture &QPicture:: operator= ( QPicture && other )

移动赋值 other 到此 QPicture 实例。

相关非成员

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

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

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

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