QLabel that prints the current number of markups that have been placed

I am trying to have a QLabel widget that prints the number of fiducials that have been placed.
I have a function called onMarkupAdded that was previously created to execute some other code when a mark up is placed. I have added to that a self.numFid = self.fiducialNode.GetNumberOfMarkupsAdded() which prints the correct number if you print the variable. I am unsure how to return this value back to setup each time a new fiducial is added.

Any help is appreciate.


If I understand your question correctly (I’m struggling to understand the “return this value back to setup” part), then you need to observe the MarkupAddedEvent event of self.fiducialNode.

self.addObserver(self.fiducialNode, slicer.vtkMRMLMarkupsNode.MarkupAddedEvent, self.onMarkupAdded)

Then in onMarkupAdded you can get the number of markups the way you describe and set it as text to the QLabel.

I hope this helps!

1 Like

I didn’t mention but there are a few things to know, such as inheriting VTKObservationMixin in your class that has the onMarkupAdded function, and the argument list of that function (self,caller,event). See examples:

1 Like