Qt Image from resource file

前端 未结 3 924
小鲜肉
小鲜肉 2021-01-18 06:18

I\'m trying to insert an image to my program via resource file, which is like:


    
        green.png&l         


        
3条回答
  •  借酒劲吻你
    2021-01-18 06:27

    First of all, you need to create a .qrc file and add image folder to it

    1. (image folder must be contained inside of the project folder)
    2. Right-click on the project file
    3. Add New
    4. Qt
    5. Qt Resource File press Choose and do other steps
    6. after opening .qrc file you must press Add > Add Prefix > change prefix name if you want
    7. again Add > Add File > and choose your images
    8. then go to mainwindow.cpp (in my project ) file and call the images as below code

      • in my case the icon folder is Playericons
    ui->play->setIcon(QIcon(":/Playericons/icons8-pause-30.png"));
    

提交回复
热议问题