1、设置icon本身大小
QLabel* label = new QLabel(this); // Assuming 'this' is a QWidget
QIcon icon(":/path/to/icon.png"); // Replace with your icon path
QPixmap pixmap = icon.pixmap(icon.availableSizes().first());
label->setPixmap(pixmap);
label->setFixedSize(pixmap.size());
2、设置指定大小
QLabel* label = new QLabel(this); // Assuming 'this' is a QWidget
QIcon icon(":/path/to/icon.png"); // Replace with your icon path
// Convert the QIcon to QPixmap
QPixmap pixmap = icon.pixmap(icon.availableSizes().first());
// Set the pixmap to the label
label->setPixmap(pixmap);
// Optional: Adjust the size of the label to the size of the pixmap
label->setFixedSize(pixmap.size());