How to set image on QPushButton?

前端 未结 8 425
时光说笑
时光说笑 2020-11-30 21:34

I want to set an image on QPushButton, and the size of QPushButton should depend on the size of the image. I am able to do this when using QL

相关标签:
8条回答
  • 2020-11-30 22:17

    Just use this code

    QPixmap pixmap("path_to_icon");
    QIcon iconBack(pixmap);
    

    Note that:"path_to_icon" is the path of image icon in file .qrc of your project You can find how to add .qrc file here

    0 讨论(0)
  • 2020-11-30 22:26

    You can do this in QtDesigner. Just click on your button then go to icon property and then choose your image file.

    0 讨论(0)
提交回复
热议问题