Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Transfer mouse events on the masked region of a QWidget to it's parent

    General and Desktop
    1
    2
    1082
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S
      SajasKK last edited by

      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&#40;&#41;;
      

      }
      @

      !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?

      1 Reply Last reply Reply Quote 0
      • S
        SajasKK last edited by

        Sorry, I made a mistake. Instead of creating the MyMainWindow I created QMainWindow. Now it's working

        1 Reply Last reply Reply Quote 0
        • First post
          Last post