PDA

View Full Version : Using QWidget::setMask(...) to create non rectangular custom push buttons



Dreamerzz
13th July 2011, 19:36
I Have been using the style sheets to edit custom states to make my own push button.

How can you use the setMask() feature to hide out the alpha areas of the picture used in the push button so when you click on a transparent area it does not set off the click?

Thanks!

heres my style sheet



QPushButton:enabled{
border-image: url(:/Button1/triangle.png) 4 4 4 4 stretch stretch;
}

QPushButton:hover{
border-image: url(:/Button1/normal.png) 4 4 4 4 stretch stretch;
}

QPushButton:pressed {
border-image: url(:/Button1/pressed.png) 4 4 4 4 stretch stretch;
}


and this was what i tried in order to make the triangle alpha areas work, (to no success)


QPixmap pixmap(":/Button1/triangle.png");
ui->pushButton->setMask(pixmap.mask());


I am aware that I could also create my own custom class which inherits from QLabel that recognizes clicks, however I'm still not too sure how to mask certain things


Help would be appreciated!
Thanks

high_flyer
14th July 2011, 11:50
QPixmap pixmap(":/Button1/triangle.png");
ui->pushButton->setMask(pixmap.mask());
This code looks ok to me.
Are you sure the transparent areas in your png are really alpha=0? maybe its not 100% transparent?

Dreamerzz
14th July 2011, 15:17
It seems the error was not #include <QBitmap>

thanks!