如何使用QImage的load方法和qrc文件

 

最近的项目中要用到QImage的load方法为项目加入一个图标, 通过查找资料和自己的试验,需要修改两个地方:

(1) cpp文件

void TitleBar::LoadImages()
{
    
if (mMenuButtonImage != NULL)
        
return;

    QString file 
= QString::fromUtf8(":/Images/MenuButton.bmp");
    mMenuButtonImage 
= new QImage();
    mMenuButtonImage
->load(file, "BMP");
}

 

(2) Image.qrc文件

<!DOCTYPE RCC><RCC version="1.0">
<qresource>
   
<file>Images/ExtractEdges.ico</file>
   
<file>Images/OpenFile.ico</file>
    
<file>Images/MenuButton.bmp</file>
</qresource>
</RCC>

 

也就是,用QString::fromUtf8得到文件的路径,然后修改qrc文件,将Image的信息加到qrc文件中,这样就可以使用了.

 

 

相关文章:

  • 2021-11-11
  • 2021-07-24
  • 2022-12-23
  • 2022-02-06
  • 2021-06-02
  • 2022-12-23
  • 2023-03-28
  • 2021-11-27
猜你喜欢
  • 2021-12-31
  • 2022-12-23
  • 2022-12-23
  • 2021-05-12
  • 2022-12-23
  • 2022-12-23
  • 2021-10-22
相关资源
相似解决方案