开发者

How to create a QPicture from a resource in Qt?

开发者 https://www.devze.com 2023-01-02 10:58 出处:网络
I have a resource at :images/pic.gif Can I make a QPicture from this resource or does it have to开发者_如何学C be loaded from file?QPicture is for recording QPainter commands, not for image data.

I have a resource at :images/pic.gif

Can I make a QPicture from this resource or does it have to开发者_如何学C be loaded from file?


QPicture is for recording QPainter commands, not for image data. If you want to load an image, use QPixmap or QImage. You can use their load() methods. To access an image file bundled as a resource, use ":/" to access the resource: ":/someFile.png". The exact paths and filenames are specified in the qrc files.


I think your question is like after adding images/pic.gif into the resource file whether it has to be accessed from the resource file or the directly the location of images/pic.gif.

Now my answer for the question is, even if you have added the images into resource file and accessing it, it will indirectly access the physical file itself. To illustrate this, after adding the images/pic.gif into the resource file, try removing the images/pic.gif from the location and access within your application. You will not able to get the image. So, even if you add it into the resource file it is similar to access the physical file present in its original location. Check out the Qt Resources page.

But it is a good practice and logical to organize your required files into a resource file so that all the required files are present in the same location.

Using QPicture you can load it into your application through

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


you have to use Qicon or Qpixmap to load the images from resource. QPIcture is used to save the picture.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号