Adding image to QPushButton on Qt

℡╲_俬逩灬. 提交于 2019-12-25 05:24:15

问题


I'm fairly new to C++ in general, so I need a little help with Qt. I'm trying to add an image to a PushButton, and I keep having problems with it. Here is an example of what I have:

#include <QtWidgets/QPushButton>
QPushButton *button;
button = new QPushButton(Example);
button->setObjectName(QStringLiteral("button"));
button->setGeometry(0,0,128,56);

So I have a picture saved in /example/pics/example.png (example being the project name), and I would like to use it on the PushButton. I've been messing around with it for a while, and can't find a solution, so any help is appreciated.


回答1:


button->setIcon(QIcon("/example/pics/example.png"));


来源:https://stackoverflow.com/questions/18328131/adding-image-to-qpushbutton-on-qt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!