1.位图资源加载方法:待补充
代码
#include "widget.h" #include "ui_widget.h" #include <QIcon> #include <QPixmap> Widget::Widget(QWidget *parent) : QWidget(parent) , ui(new Ui::Widget) { ui->setupUi(this); setGeometry(100, 100, 200, 100); pushButton = new QPushButton(QIcon(":/1.PNG"), "", this); // 按钮构造函数指定按钮的图标及父窗口 pushButton->setIconSize(QSize(50, 50)); // 设置图标长宽为50 //QIcon(QPixmap(":/1.PNG").scaled(pushButton1->rect().size())) pushButton->setGeometry(10,10, 50, 50); QIcon button_ico(":/2.PNG"); // 位图构造函数指定图标路径 pushButton1 = new QPushButton("", this); // 按钮1构造指定父窗口 pushButton1->setGeometry(10,200, 50, 50); // 设置串口起始坐标及长款 pushButton1->setIcon(button_ico); // 设置按钮1位图 pushButton1->setIconSize(QSize(50, 50)); // 设置位图大小 } Widget::~Widget() { delete ui; delete pushButton; delete pushButton1; }
Qt助手路径:Qt\Qt5.14.1\5.14.1\msvc2017_64\bin\assistant.exe (帮助文档)