Nominate our 2022 Qt Champions!

Trapping and releasing mouse input

  • I have a widget covering my screen that catches all mouse input. What I want is that when it is clicked, I decide if it should handle the mouse input or allow the mouse input to go through like the widget isn't there.

    I can't just call sendEvent() because I don't know who the input would go to. There are multiple objects underneath the area.

    How can I go about deciding to handle it or just allowing it to pass through?

  • Moderators

    i haven't found a good (Qt only) solution for myself either for this problem.
    The only thing i did which seemed to work is:
    QWidget* widget = QApplication::widgetAt(mosueEvent->globalPos());
    But this only works for widgets inside your application.

  • Thanks.

    I did the following which seems to work:
    QMouseEvent * pMouse = static_cast<QMouseEvent >(e);
    widget = QApplication::widgetAt(pMouse->globalPos());
    QApplication::sendEvent(widget, pMouse);

Log in to reply