问题
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