qSlicerMarkupsPlaceWidget - How to delete all mark-ups

Trying to learn the qSlicerMarkupsPlaceWidget Class (Slicer: qSlicerMarkupsPlaceWidget Class Reference).

Everything is good however I’d like to modify the delete button so that it deletes ALL mark-ups instead of just the last one. I’d like to modify this on my .py file however it seems like the code for Markups module is done by C++.

Not only that, as it currently stands, if I click the delete button (delete last added markup point), it only deletes the sphere balls, but not the line. I’d like to delete the line as well.

Here is my code currently:
lineNode = slicer.mrmlScene.AddNewNodeByClass(“vtkMRMLMarkupsLineNode”, ‘L’)
w=slicer.qSlicerMarkupsPlaceWidget()
w.setMRMLScene(slicer.mrmlScene)
w.setCurrentNode(lineNode)
w.buttonsVisible=False
w.placeButton().show()
w.deleteButton().show()
w.setDeleteAllMarkupsOptionVisible(True) # this doesn’t seem to change anything
w.show()
w.onVisibilityButtonClicked()
lineNode.GetDisplayNode().SetGlyphScale(0.5)

Thanks in advance

The delete all points option shows up with a long mouse press. There is an update of this widget in-progress that will change this to a drop down menu arrow, since this interface option is rarely used and can be confusing.

Which version of Slicer are you using? The place button should be updating with the current markup type, and deleting the line and last point with the delete button, or the line and both points with the delete all option. This was working for me with your code snippet.

Thanks for your reply Sara. Here is a video of what I’m experiencing: deletemarkupvideo.mov - Google Drive

As we can see, the line is persisting although the spheres can be removed.
Also, is there a way for me to edit so that instead of the long mouse press, I can delete all using a single mouse press? in the .py file.

Lastly, instead of summoning a separate tab window for the qSlicerMarkupsPlaceWidget, is there a way for me to have it stay within the 3D scene view window only?

Are you using the stable version of 3D Slicer? This behavior is caused by the widget not updating to the correct markup type, but I can’t replicate this error on my end.

You could incorporate this widget in a module, but these functions will also be available in the main toolbar in the upcoming markups update.

Very strange. Yes I’m using the latest stable version - 4.11.20210226
Could it be something related to my code? If you wouldn’t mind copying & pasting my code into yours.

And great yes I plan to incorporate the widget into my module. Would you be able to provide a brief guidance on how I can do this programmatically? Any example project that incorporates qSlicerMarkupsPlaceWidget programmatically would be great

Thanks a lot Sara!

Another weird thing I noticed was, on my python console, I get an error that it does not recognize the .onVisibilityButtonClicked() function

AttributeError: qSlicerMarkupsPlaceWidget has no attribute named ‘onVisibilityButtonClicked’

However without adding this piece of code I actually cannot see the widget at all - so I’m not sure why it would register it as an error?

I’ve downloaded the preview version 4.13.0-2021-06-30 and the ruler function seems to work fine! Thanks for all your help.

2 Likes

Hi Sara, is it just me or has placing a fiducial point become a little buggy after this update? I feel like even if I move just a little bit after I click, or don’t hold the mouse click long enough, the fiducial point does not get placed. Has there been a change in code with regards to this?

Great! If you are adding the qSlicerMarkupsPlaceWidget to a module, it might be helpful to check out the SimpleMarkupsWidget which uses this widget to see how to set the parameters.

I am also working on an update to the qSlicerMarkupsPlaceWidget which should be available in the next stable version, that will add it to the main Slicer toolbar.

1 Like

This is probably what you are seeing: Feedback requested: Requirements to place a fiducial - #15 by tomekcz

2 Likes

Great, look forward to it! :slight_smile:

Yes it is! I have to agree with the people, that for me it is not a welcomed change :frowning:

Yes agreed. I think we can come up with a better way.

Just need a consensus on how to overload the Left-click button properly so that the 3D view can be manipulated at the same time as point placement.

1 Like

Hmmm, after the update, I’m still having an issue with the delete button. Is there no way for me to delete all of the lines present?

With the current behavior, the “delete all” button removes points from the current markups node only. Removing all points from active and non-active nodes could potentially be useful, but also risky.

Are there cases where a simple “clear scene” would not work?

Oh okay. So is there no way for me to delete all of the lines using the delete button?
I do have models I’d like to keep in the scene so clear scene would not be so ideal.

Not currently. Also note that it does not delete the line node itself, will just the control points in the node.

You can go to Markups or Data module, select all the markups in the tree that you want to delete, then right-click and select Delete.