# About changing mouse cursor

**URL:** <https://discourse.slicer.org/t/about-changing-mouse-cursor/15814>\
**Category:** Development\
**Created:** [February 3, 2021, 2:21pm UTC](https://discourse.slicer.org/t/about-changing-mouse-cursor/15814 "2021-02-03T14:21:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![forfullstack](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/forfullstack/32/9751_2.png) [@forfullstack](https://discourse.slicer.org/u/forfullstack)\
**Post date:** [February 3, 2021, 2:21pm UTC](https://discourse.slicer.org/t/about-changing-mouse-cursor/15814/1 "2021-02-03T14:21:27Z")

</div>

I want to change shape of mouse cursor when mouse crosses MPR lines ![Capture](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/b/4/b485012b501dc1c6e408f7bd6ed04550bf141633.png)  
I’ve added function in the vtkMRMLSliceIntersectionWidget.cxx to check crossing with MPR lines.  
But how can I change cursor in that time? I think I have to add setCursor to the qMRMLSliceView.cxx.  
How can I send event from the vtkMRML to the qMRML? Is there anything sample doing such an action?

Thanks.

---

<div class="post-metadata">

**Author:** ![forfullstack](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/forfullstack/32/9751_2.png) [@forfullstack](https://discourse.slicer.org/u/forfullstack)\
**Post date:** [February 3, 2021, 2:32pm UTC](https://discourse.slicer.org/t/about-changing-mouse-cursor/15814/2 "2021-02-03T14:32:42Z")

</div>

Just I found a way to do it. Hope it will help everyone who wants to implement similar logic.  
// Sender  
vtkMRMLSliceIntersectionWidget::MyFunc()  
{  
crosshairNode-\>InvokeEvent(vtkMRMLCrosshairNode::MyEvent, nullptr);  
}

// Handler  
void qMRMLSliceControllerWidgetPrivate::setAndObserveCrosshairNode()  
{  
this-\>qvtkReconnect(nullptr, crosshairNode, vtkMRMLCrosshairNode::MyEvent,  
q, SLOT(MyHandler()));  
}

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [February 3, 2021, 3:38pm UTC](https://discourse.slicer.org/t/about-changing-mouse-cursor/15814/3 "2021-02-03T15:38:11Z")

</div>

It is great that you are adding this feature. We have created the slice intersection widget to allow exactly this and also to make it easier to customize the behavior (e.g., drag-and-drop slice intersection line to move/rotate slice intersection instead of Shift+MouseMove and Ctrl+Alt+Left-click-and-drag).

To change the mouse cursor, please update the displayable manager’s `GetMouseCursor()` method. Since the crosshair is already a widget, all you need to do is to ask the widget what is the desired cursor shape, similarly how it is done in [markups displayable manager](https://github.com/Slicer/Slicer/blob/08789e8f2224f89206b2d6a49d1d452d4e677994/Modules/Loadable/Markups/MRMLDM/vtkMRMLMarkupsDisplayableManager.cxx#L925-L931).

---

<div class="post-metadata">

**Author:** ![forfullstack](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/forfullstack/32/9751_2.png) [@forfullstack](https://discourse.slicer.org/u/forfullstack)\
**Post date:** [February 5, 2021, 3:11am UTC](https://discourse.slicer.org/t/about-changing-mouse-cursor/15814/4 "2021-02-05T03:11:01Z")

</div>

Hello Andras,  
Thanks for your reply.  
Just I was become known there already exists virtual function named GetMouseCursor().  
vtkMRMLAbstractDisplayableManager and his child class vtkMRMLMarkupsDisplayableManager have this function.  
Also vtkMRMLAbstractWidget and his child class vtkSlicerMarkupsWidget have that one.  
I added logging function in the above all GetMouseCursor() and found only vtkMRMLAbstractDisplayableManager’s GetMouseCursor() is working.  
I think displayable manager’s GetMouseCursor() should call its widget’s GetMouseCursor() then my logic is able to work.  
Unfortunately vtkMRMLAbstractDisplayableManager does not have widget member as vtkMRMLMarkupsDisplayableManager has LastActiveWidget.  
So currently there’s no way to call widget’s GetMouseCursor() from the displayable manager.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [February 5, 2021, 3:17am UTC](https://discourse.slicer.org/t/about-changing-mouse-cursor/15814/5 "2021-02-05T03:17:16Z")

</div>

> [@forfullstack](#):
>
> Unfortunately vtkMRMLAbstractDisplayableManager does not have widget member as vtkMRMLMarkupsDisplayableManager has LastActiveWidget.

vtkMRMLCrosshairDisplayableManager has the SliceIntersectionWidget widget. You can ask that widget what cursor shape it wants and set that in the renderer, similarly how it is done in markups.

---

<div class="post-metadata">

**Author:** ![forfullstack](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/forfullstack/32/9751_2.png) [@forfullstack](https://discourse.slicer.org/u/forfullstack)\
**Post date:** [February 5, 2021, 9:52am UTC](https://discourse.slicer.org/t/about-changing-mouse-cursor/15814/6 "2021-02-05T09:52:26Z")

</div>

I added GetMouseCursor() on the vtkMRMLCrosshairDisplayableManager and let it to call vtkMRMLSliceIntersectionWidget::GetMouseCursor() and it’s working.  
But really mouse cursor isn’t changed despite of GetMouseCursor() returns VTK\_CURSOR\_CROSSHAIR.  
I think somewhere it hooks mouse cursor.  
Anyway thanks for your answer and I have learned some event handlings more.  
I have more issues and will ask you.
