2

I can do something when mouse is moving by overwriting QWidget's mouseMoveEvent function.

But I want to do something at the moment when mouse stop moving. How can I implement this?

  • Add some code, what have you tried so far? Are you having any issues with implementing it or are you just unsure? If you're unsure, I recommend taking the time to do your own research. –  Feb 13 '19 at 22:43

1 Answers1

3

I would recommend using a single-shot QTimer that you restart each time mouseMoveEvent is called. Set the timeout to some threshold of your choosing. For example:

class Widget : public QWidget
{
public:
  Widget(QWidget *parent = nullptr)
    : QWidget(parent)
  {
    setMouseTracking(true);
    mTimer.setInterval(500);
    mTimer.setSingleShot(true);
    connect(&mTimer, &QTimer::timeout, [] {
      qDebug("Mouse stopped moving!!!");
    });
  }

  void mouseMoveEvent(QMouseEvent *event) override
  {
    mTimer.start();
  }

private:
  QTimer mTimer;
};
Jason Haslam
  • 2,617
  • 13
  • 19