QWidget.setMask() problem
-
Hi! I can't create a button, which must have image's shape. Image (PNG) have transparent areas, and I want to clip mouse events on transparent areas...
I have tried 2 ways, but mouse events whatever works in transparent area:- reimplement paintEvent:
[code]
painter.setClipping( true );
painter.setClipRect( 0, 0, width(), height() );
painter.setClipRegion(QRegion(QRect(rect())).subtracted(QRegion(QBitmap( imagePixmap))));
painter.drawPixmap( rect(), imagePixmap );
[/code] - btn.setMask:
[code]
setMask( QBitmap( imagePixmap ) );
[/code]
and just in case I have reimplemented mouseMoveEvent:
[code]
if( !mask().contains( event->pos() ) )
{
return; //exit from handling
}
[/code]What to do?)
- reimplement paintEvent:
-
ad 1):
doing anything related to mouse events wont work since the paintEvent()'s purpose is just drawingas 2)
i think the mask only works for top-level widget...but i'm not sure right now.
But you may also want to check if the QBitmap is correct by saving it to a file and check it if black and white colors are correct and what are you expecting.
@
QBitmap bitmap( imagePixmap );
bitmap.save("<any-file-path>");
@ad 3)
i don't know which mouse events you mean, but i think you mean mouse clicks? If so you should rather do this in mousePressEvent() and mouseReleaseEvent()