# Add or maintain window level preset

**URL:** <https://discourse.slicer.org/t/add-or-maintain-window-level-preset/24606>\
**Category:** Support\
**Created:** [August 2, 2022, 7:29pm UTC](https://discourse.slicer.org/t/add-or-maintain-window-level-preset/24606 "2022-08-02T19:29:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rhodesdante](https://avatars.discourse-cdn.com/v4/letter/r/dec6dc/32.png) [@rhodesdante](https://discourse.slicer.org/u/rhodesdante)\
**Post date:** [August 2, 2022, 7:29pm UTC](https://discourse.slicer.org/t/add-or-maintain-window-level-preset/24606/1 "2022-08-02T19:29:47Z")

</div>

I am trying to create a window/level preset so it pops down on right-click of the slice panes, or make a previous manual preset “sticky”, as described [here](https://github.com/Project-MONAI/MONAILabel/issues/447). I would prefer to do the sticky option, because the person for whom I am implementing this is interrogating a lot of volumes back-to-back. However, I’m not really sure where to start with this. I’ve made python modules before, but this seems like I would need to write something in the C++ code for the application, perhaps [here](https://github.com/Slicer/Slicer/blob/main/Modules/Loadable/Data/qSlicerDataModuleWidget.cxx). Are there any tips for how I should go about implementing such a feature? Thanks so much for your support!

---

<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:** [August 3, 2022, 5:48pm UTC](https://discourse.slicer.org/t/add-or-maintain-window-level-preset/24606/2 "2022-08-03T17:48:38Z")

</div>

When Slicer loads an image, it uses the window/level that is stored in the image file. If the image is loaded from a research format, which does not store display settings then the window/level is automatically computed from the image content.

You can add or modify window/level presets in this file:

```
<SlicerHome>\share\Slicer-5.0\qt-loadable-modules\Volumes\VolumeDisplayPresets.json

```

You can copy-paste these few lines of of Python code into the Python console if you want to apply a custom window/level preset when a node is loaded:

```python
@vtk.calldata_type(vtk.VTK_OBJECT)
def onNodeAdded(caller, event, node):
    if isinstance(node, slicer.vtkMRMLScalarVolumeDisplayNode):
        # Call using a timer instead of calling it directly to allow the volume loading to fully complete.
        qt.QTimer.singleShot(0, lambda: setCustomWindowLevel(node))

def setCustomWindowLevel(displayNode):
    displayNode.SetAutoWindowLevel(False)
    displayNode.SetWindowLevel(16, 128)

slicer.mrmlScene.AddObserver(slicer.vtkMRMLScene.NodeAddedEvent, onNodeAdded)

```

---

<div class="post-metadata">

**Author:** ![rhodesdante](https://avatars.discourse-cdn.com/v4/letter/r/dec6dc/32.png) [@rhodesdante](https://discourse.slicer.org/u/rhodesdante)\
**Post date:** [August 3, 2022, 6:33pm UTC](https://discourse.slicer.org/t/add-or-maintain-window-level-preset/24606/3 "2022-08-03T18:33:22Z")

</div>

Thank you very much!
