Print dataprobe text with shift key

I would like to print the background scalarVolume value where the crosshair is when it is repositioned with Shift key.

Here is my code, it doesn’t work:

def probeBackgroundVolumeOverMouse():
    infoWidget = slicer.modules.DataProbeInstance.infoWidget
    if infoWidget.layerValues['B'].text == '':
    cleanedTextOfDataProbe = infoWidget.layerValues['B'].text.split('<b>')[1].split('</b>')[0]
    if cleanedTextOfDataProbe.isdecimal():
    elif cleanedTextOfDataProbe[1:].isdecimal():

shortcut = qt.QShortcut(slicer.util.mainWindow())
shortcut.setKey(qt.QKeySequence('Shift')) #this doesn't work
#shortcut.setKey(qt.QKeySequence('.')) #this does work

I guess there is some conflict because the Shift key is already used.

Really I’m just trying to get the value of the scalarVolume where the crosshair is. This is the first method that came to my mind but others are welcomed. Although retrieving the value using the Shift key is very important so it keeps it simple for the user.

So you’re trying to replicate the DataProbe module? Do you not want this updated value on the cursor position moved event? The DataProbe module gets this value by doing the following:

1 Like

Thanks. That’s very useful

Hi @jamesobutler. I’ve got to reuse the code of the dataProbe but I still cannot execute my function on shift key press. Is this reacheable in Python? I was able to detect them on the sliceInteractor but I would prefer them to be detected on the mainWindow because sliceInteractor doesn’t react if it is not “selected” (i.e. it hasn’t been clicked inside)

I tried but just using the shift key did not work for me.

@lassoan Do you have any suggestions on how to execute a callback by pressing the shiftkey? Is it possible on Python? Ideally the callback would be called multiple times while shift is still pressed.

All of this I don’t think will work. This all sounds like a mouse move event as is done already with the DataProbe module.

One call per press would be fine anyway.

I presented a simplified version of my problem. I need to use the sampled HU value as input for a process of the logic.

Crosshair node is intended for continuous sampling. For taking discrete samples I would recommend to use markup points node. If you don’t want to allow your users to change the input points then you can immediately hide or delete the point after it has been placed.

1 Like