# How to capture mouse move event?

**URL:** https://discourse.vtk.org/t/how-to-capture-mouse-move-event/6995
**Category:** Development
**Created:** [October 27, 2021, 5:53pm UTC](https://discourse.vtk.org/t/how-to-capture-mouse-move-event/6995 "2021-10-27T17:53:56Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Cameron](https://discourse.vtk.org/user_avatar/discourse.vtk.org/cameron/32/4063_2.png) [@Cameron](https://discourse.vtk.org/u/Cameron)
#### Post date: [October 27, 2021, 5:53pm UTC](https://discourse.vtk.org/t/how-to-capture-mouse-move-event/6995/1 "2021-10-27T17:53:56Z")

</div>

I am struggling with capturing mouse move event.  
e.g. I have this custom style and set it to the interactor.

```auto
namespace {

  class vtkMouseMoveStyle : public vtkInteractorStyleTrackballCamera
  {
  public:
    static vtkMouseMoveStyle* New();
    vtkTypeMacro(vtkMouseMoveStyle, vtkInteractorStyleTrackballCamera);

    virtual void OnLeftButtonUp() override
    {
      // Forward events
      vtkInteractorStyleTrackballCamera::OnLeftButtonUp();

      
    }

    virtual void OnMouseMove() override
    {
        std::cout << "Mouse moved!";
    }
  };

  vtkStandardNewMacro(vtkMouseMoveStyle);

} // namespace

```

But the OnMouseMove() method here only fires when I am holding left/right button and moving my mouse.  
I would like to capture the event as soon as the cursor location changes inside the viewport. Can anyone point me to the right direction?

Thanks,  
Cameron

---

<div class="post-metadata">

### Author: ![codeling](https://discourse.vtk.org/user_avatar/discourse.vtk.org/codeling/32/3792_2.png) [@codeling](https://discourse.vtk.org/u/codeling)
#### Post date: [October 28, 2021, 7:47am UTC](https://discourse.vtk.org/t/how-to-capture-mouse-move-event/6995/2 "2021-10-28T07:47:18Z")

</div>

Are you using Qt by any chance? In Qt, you have to [enable mouse tracking](https://doc.qt.io/qt-5/qwidget.html#mouseTracking-prop) in order to get mouse move events also when no button is pressed.
