0

I'm working on a custom slider on Qt, so I have a widget and a Slider in it promoted to my class called CustomSlider. In this class I'm using PaintEvent to draw some markers and an EventFilter to catch the mouse when hovers over those markers to show some message. The problem is that the event is being triggered unpredictably. I noticed that if i keep the button of my mouse pressed always work. But without pressing any button, works sometimes.

In my CustomSlider.cpp constructor I have setMouseTracking(true); to tracking the mouse and CustomSlider::installEventFilter(this); to install the event.

And my EventFilter function is something like:

bool CustomSlider::eventFilter(QObject* obj, QEvent* e)
{
    if (obj == this && e->type() == QEvent::MouseMove)
    {
        QMouseEvent* event = static_cast<QMouseEvent*>(e);
        // Do something
        return true;
    }
    return QObject::eventFilter(obj, e);
}

How I said, this works fine sometimes, but in some points is not and only works if I keep the button pressed. Any idea what could be wrong?

BinaryTalk
  • 33
  • 5
  • `setMouseTracking(true)` is good and necessary; with that you can get rid of the `installEventFilter(this)` call and the `eventFilter()` method-override and just override `mouseMoveEvent(QMouseEvent *)` instead. – Jeremy Friesner Feb 22 '23 at 22:41

0 Answers0