0

I have the following widget's hierarchy:

root (QWidget)
 |-> first child (QWidget)
 |---> label A (QLabel)
 |---> label B (QLabel)
 |-> second child (QButton)
 |-> third child (QButton)

what I am trying to achieve is to receive mouse release events on first child (or both label A and label B, the behaviour would be the same anyway)

I tried using an event filter

MyWidget(QWidget* parent) : QWidget(parent) {
    setupUi(this);
    // some other stuff
    mFirstChild->installEventFilter(this);
}

bool MyWidget::eventFilter(QObject* object, QEvent* event) {
    if (event->type() == QEvent::MouseButtonRelease) {
        // do stuff
        return true;
    }
    return QWidget::eventFilter(object, event);
}

My problem is that my test doStuff() method is never called. I correctly receive events like Enter, Leave, Repaint, MousePress, MouseDblClick, but I never get MouseRelease (nor MouseMove by the way). Am I missing something obvious here ?

EDIT: After some more researches, I tried using WA_TransparentForMouseEvents attribute, it did not change anything.

cmourglia
  • 2,423
  • 1
  • 17
  • 33
  • No focus probably. You only have the mouse button release event within the viewport area of first child. i. e. if you move the mouse to second child and then release your mouse button it will not trigger your installed MouseButtonRelease event. Same if another child is on top. – user3606329 Oct 23 '17 at 21:15
  • What should I do then ? Force the focus on the mouse press event ? – cmourglia Oct 24 '17 at 06:23
  • 1
    Your code should work as expected. If the mouse is released in the viewport of the first children an event should occur. – user3606329 Oct 24 '17 at 20:55
  • For debugging further Please check "class CustomGUIApplication: public QGuiApplication {public: CustomGUIApplication(int &argc, char **argv) :QGuiApplication(argc, argv) { } virtual bool notify(QObject *receiver, QEvent *e) override { return QGuiApplication::notify(receiver, e); //Check whether you are getting events at this point. } };" – Ashif Oct 25 '17 at 14:07
  • For mouse move event try to enable http://doc.qt.io/qt-5/qwidget.html#mouseTracking-prop – Ashif Oct 25 '17 at 14:11
  • Thanks for the insights. Actually I do not need mouse events, it was more for providing additional infos. I will give a shot at your debbuging tip, thanks. – cmourglia Oct 25 '17 at 15:00

0 Answers0