您基本上需要使用Qt资源系统.在这里
查看Compiled-In Resources .
让我们说这是你的资源文件
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file>images/copy.png</file>
<file>images/cut.png</file>
<file>images/paste.png</file>
</qresource>
</RCC>
Run Code Online (Sandbox Code Playgroud)
在您的源代码中,您现在可以通过引用资源中的图像来创建QIcons
QIcon(":/images/cut.png")
Run Code Online (Sandbox Code Playgroud)
不要忘记在.pro中引用资源文件
RESOURCES = application.qrc
Run Code Online (Sandbox Code Playgroud)
此示例使用资源文件中的图像作为图标
作为Qt资源系统的替代方案,您可以使用(您最喜欢的图像转换实用程序)将.png文件转换为.xpm格式,然后将这些行添加到.cpp文件中:
#include "my_converted_image.xpm"
[...]
QPixmap myPixmap((const char **) my_converted_image_xpm);
Run Code Online (Sandbox Code Playgroud)
...其中my_converted_image_xpm是在.xpm文件顶部附近声明的字符数组的名称.这是因为.xpm图像格式实际上只是C源代码,声明了一个字符数组,即位图,QPixmap知道如何解析,例如:
/* XPM */
static const char * const my_converted_image_xpm[] = {
"16 16 65 1",
" c None",
". c #0F0F04",
[...]
" "};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2254 次 |
| 最近记录: |