# Right-click context menu in slice views

**URL:** <https://discourse.slicer.org/t/right-click-context-menu-in-slice-views/25056>\
**Category:** Development\
**Created:** [September 2, 2022, 7:58pm UTC](https://discourse.slicer.org/t/right-click-context-menu-in-slice-views/25056 "2022-09-02T19:58:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![giovform](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/giovform/32/4687_2.png) [@giovform](https://discourse.slicer.org/u/giovform)\
**Post date:** [September 2, 2022, 7:58pm UTC](https://discourse.slicer.org/t/right-click-context-menu-in-slice-views/25056/1 "2022-09-02T19:58:17Z")

</div>

How can I programatically disable (and enable again) the right-click context menu in slice views?

---

<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:** [September 2, 2022, 9:40pm UTC](https://discourse.slicer.org/t/right-click-context-menu-in-slice-views/25056/2 "2022-09-02T21:40:50Z")

</div>

You can configure this at multiple levels. If you just want to disable all actions in all views then you can set an empty list for the [allowed context menu action names](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#use-allowlist-to-customize-view-menu). If you just want to disable right-click action in certain views then you can remove the right-click GUI event translation ([assign the right-click GUI event](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#custom-shortcut-for-moving-crosshair-in-a-slice-view) to `vtk.vtkWidgetEvent.NoEvent` widget event).

---

<div class="post-metadata">

**Author:** ![codeling](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/codeling/32/81200_2.png) [@codeling](https://discourse.slicer.org/u/codeling)\
**Post date:** [March 17, 2026, 3:22pm UTC](https://discourse.slicer.org/t/right-click-context-menu-in-slice-views/25056/4 "2026-03-17T15:22:51Z")

</div>

I believe the input handling has been considerably reworked lately, I can’t figure out how disabling the context menu in current slicer(main branch) would work (3D view / slice views). I tried via displayable manager, but seems I can’t register vtkCommand::RightButtonPressEvent - my ProcessEvents is never called

---

<div class="post-metadata">

**Author:** ![codeling](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/codeling/32/81200_2.png) [@codeling](https://discourse.slicer.org/u/codeling)\
**Post date:** [March 18, 2026, 12:29pm UTC](https://discourse.slicer.org/t/right-click-context-menu-in-slice-views/25056/5 "2026-03-18T12:29:46Z")

</div>

I also tried via `qSlicerSubjectHierarchyPluginLogic::setAllowedViewContextMenuActionNames`, as suggested above, but setting the allowed actions to empty does not seem to work. When I look at the check in `buildMenuFromActions`, it looks like this:

```auto
if (!allowedActions.isEmpty() && !allowedActions.contains(action->objectName()))

```

and thus considers an empty list as “all actions allowed”, right?

I have now a workaround based on eventFilter - I block the right button pressed/released event for the QVTKOpenGLNativeWidget of the respective 3D / slicer view; this is the best I could come up with so far which works, but maybe someone has a better solution?

---

<div class="post-metadata">

**Author:** ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)\
**Post date:** [March 18, 2026, 1:10pm UTC](https://discourse.slicer.org/t/right-click-context-menu-in-slice-views/25056/6 "2026-03-18T13:10:03Z")

</div>

I recently had to customize this menu and after trying many things ended up doing this:

```auto
  @staticmethod
  def showSubjectHierarchyContextMenuActions(show) -> None:
    """
    Show or hide subject hierarchy context menu actions that are not relevant in custom app mode.
    """
    pluginHandler = slicer.qSlicerSubjectHierarchyPluginHandler.instance()
    viewContextMenuPlugin = pluginHandler.pluginByName('ViewContextMenu')
    viewContextMenuActions = slicer.util.findChildren(viewContextMenuPlugin, className='QAction')
    actionTexts = ["Place", "Adjust window/level", "View transform", "Configure slice view annotations..."]
    for action in viewContextMenuActions:
      if action.text in actionTexts:
        # action.visible = show #TODO: This does not have effect (shown at context menu building)
        action.enabled = show

```

Back then I didn’t want to spend time modifying the core, so had to do a workaround… It would make sense to make this possible from the API.
