#include#include QIcon icon("my_icon.png"); QSize size = icon.actualSize(QSize(64, 64)); QLabel label; label.setPixmap(icon.pixmap(size));
#includeIn this example, we create a custom QToolButton subclass called ScalingToolButton. The class takes an icon path as a parameter and sets the button's icon to the scaled icon returned by actualSize() on the QIcon object created from the icon path. We use the setIconSize() method to set the fixed size of the icon to be 32x32 pixels. We then create an instance of ScalingToolButton and pass in the icon path and the parent widget as parameters. Package/Library: Qt library.#include class ScalingToolButton : public QToolButton { public: ScalingToolButton(const QString &iconPath, QWidget *parent = nullptr) : QToolButton(parent) { QIcon icon(iconPath); setIconSize(icon.actualSize(QSize(32, 32))); setIcon(icon); } }; // Usage: ScalingToolButton *button = new ScalingToolButton("my_icon.png", parentWidget);