Transfer mouse events on the masked region of a QWidget to it's parent
-
I have a QMainWindow which contains a circular QWidget inside it. In order to have a circular shaped QWidget I am making use of QWidget::setMask. The intended behaviour of the application on mouse press is inside the MainWindow depends on the region on which mouse is pressed.
@class MyMainWindow: public QMainWindow
{
public:
MyMainWindow():QMainWindow()
{} void mousePressEvent( QMouseEvent * event ) { qDebug()<<"Clicked on MainWindow"; }
};
class CircularWidget: public QWidget
{
public:
CircularWidget( QWidget * parent ):QWidget( parent )
{} void paintEvent(QPaintEvent * event) { QRegion circularMask( QRect( pos(), size() ), QRegion::Ellipse ); setMask( circularMask ); setStyleSheet("background-color:black;"); QWidget::paintEvent( event ); } void mousePressEvent( QMouseEvent * event ) { qDebug()<<"Clicked on Circular Widget"; }
};
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QMainWindow w;
w.resize( 400, 400 );CircularWidget circularWidget( &w ); circularWidget.show(); w.setCentralWidget( &circularWidget ); w.show(); return a.exec();
}
@!http://i.stack.imgur.com/PCMYS.png(MyWindow)!
Currently, when I click inside the circular region I get the event in my Widget. But all the mouse press events outside the circle are lost. I saw in the Qt Documentations that: Masked widgets receive mouse events only on their visible portions. Is there any way to transfer the other mouse click events (events on the grey region in the picture) to the parent widget?