将图像添加到Qt上的QPushButton [英] Adding image to QPushButton on Qt

查看:104
本文介绍了将图像添加到Qt上的QPushButton的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一般来说对C ++还是陌生的,所以我需要Qt的帮助.我正在尝试将图像添加到PushButton,但是我一直在遇到问题.这是我所拥有的示例:

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);

所以我有一张图片保存在/example/pics/example.png中(示例是项目名称),我想在PushButton上使用它.我一直在搞乱它一段时间,找不到解决方案,所以能提供任何帮助.

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.

推荐答案

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

这篇关于将图像添加到Qt上的QPushButton的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆