Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Transfer mouse events on the masked region of a QWidget to it's parent
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 1.2k Views
  • 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 Offline
    S Offline
    SajasKK
    wrote on last edited by
    #1

    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
    0
    • S Offline
      S Offline
      SajasKK
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved