I would like to have a button with the shape of its icon image in my QT application. I’m trying to set the button mask by obtaining the mask from the used image (.png) using the alpha channel.
Here are the interested code lines:
QPushButton button();
QPixmap pixmap("image_path.png");
QIcon icon(pixmap);
button.setIcon(icon);
button.setMask(pixmap.createMaskFromColor(Qt::transparent,Qt::MaskInColor));
The result is that the button disappears!
By doing some tests I’m sure that the mask is created rightly, where is the mistake?
if you’re using a .png with alpha like this one :

you can set its shape as a mask like this:
You will got a result like :
