网站地图    收藏   

主页 > 前端 > css教程 >

Qt4--创建自定义图标 - html/css语言栏目:html.css

来源:自学PHP网    时间:2015-04-14 14:51 作者: 阅读:

[导读] 1、通过Qt Assistant 查看 Qt resource system原文:The Qt resource system is a platform-independent mechanism for storing binary files in the application#39;s executable. This ......

1、通过Qt Assistant 查看 Qt resource system

原文:The Qt resource system is a platform-independent mechanism for storing binary files in the application's executable. This is useful if your application always needs a certain set of files (icons, translation files, etc.) and you don't want to run the risk of losing the files.

 

 

意思是说,Qt resource system是和平台无关,他用来为应用程序存储二进制文件。如果在运行过程中不想要冒文件丢失的险,这样的文件集就是一个很好的选择。

 


原文:The resources associated with an application are specified in a .qrc file, an XML-based file format that lists files on the disk and optionally assigns them a resource name that the application must use to access the resource.

Here's an example .qrc file:


 

 DOCTYPE RCC><RCC version="1.0"> 
 <qresource> 
     <file>images/copy.png</file> 
     <file>images/cut.png</file> 
     <file>images/new.png</file> 
     <file>images/open.png</file> 
     <file>images/paste.png</file> 
     <file>images/save.png</file> 
 </qresource> 
 </RCC> 

<!DOCTYPE RCC><RCC version="1.0">
 <qresource>
     <file>images/copy.png</file>
     <file>images/cut.png</file>
     <file>images/new.png</file>
     <file>images/open.png</file>
     <file>images/paste.png</file>
     <file>images/save.png</file>
 </qresource>

 </RCC>这些资源被存放在.qrc文件下,这是一个基于XML格式的文件。

 

原文:For a resource to be compiled into the binary the .qrc file must be mentioned in the application's .pro file so that qmake knows about it. For example:
 

RESOURCES     = application.qrc 

 RESOURCES     = application.qrc需要在.pro文件内加入.qrc文件

 

如下图是qmake以后生产的文件。也就是程序中可以用如“:/images/copy.png”

 

 

 


原文:

Using Resources in the Application

In the application, resource paths can be used in most places instead of ordinary file system paths. In particular, you can pass a resource path instead of a file name to the QIcon, QImage, or QPixmap constructor:

 cutAct = new QAction(QIcon(":/images/cut.png"), tr("Cu&t"), this); 

cutAct = new QAction(QIcon(":/images/cut.png"), tr("Cu&t"), this);


2、示例
1、在目录下建立images文件夹,在文件夹内放入图片:buttonico.png

 

 


2、建立一个Qt resource 文件,取名为images.qrc

 

 

 

3、修改images.qrc文件内容

 


修改好以后Qt Creator内images.qrc发生变化

 

 

 

4、创建main.cpp


 

 include<QApplication>  
#include<QPushButton>  
 
int main(int argc, char* argv[]) 
{ 
    QApplication app(argc, argv); 
 
    QPushButton* button = new QPushButton(); 
    button->setIcon(QIcon(":/images/buttonico.png")); 
    QObject::connect(button, SIGNAL(clicked()), &app, SLOT(quit())); 
    button->show(); 
    return app.exec(); 
} 

 

自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习

京ICP备14009008号-1@版权所有www.zixuephp.com

网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com

添加评论