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

**URL:** <https://discourse.slicer.org/t/qlabel-that-prints-the-current-number-of-markups-that-have-been-placed/2094>\
**Category:** Support\
**Created:** [February 15, 2018, 10:20pm UTC](https://discourse.slicer.org/t/qlabel-that-prints-the-current-number-of-markups-that-have-been-placed/2094 "2018-02-15T22:20:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lgroves](https://avatars.discourse-cdn.com/v4/letter/l/4af34b/32.png) [@lgroves](https://discourse.slicer.org/u/lgroves)\
**Post date:** [February 15, 2018, 10:20pm UTC](https://discourse.slicer.org/t/qlabel-that-prints-the-current-number-of-markups-that-have-been-placed/2094/1 "2018-02-15T22:20:55Z")

</div>

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.

Thanks!

---

<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:** [February 16, 2018, 9:26pm UTC](https://discourse.slicer.org/t/qlabel-that-prints-the-current-number-of-markups-that-have-been-placed/2094/2 "2018-02-16T21:26:04Z")

</div>

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!

---

<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:** [February 16, 2018, 9:29pm UTC](https://discourse.slicer.org/t/qlabel-that-prints-the-current-number-of-markups-that-have-been-placed/2094/3 "2018-02-16T21:29:58Z")

</div>

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:

- [https://github.com/Slicer/Slicer/blob/master/Modules/Scripted/SegmentStatistics/SegmentStatistics.py](https://github.com/Slicer/Slicer/blob/master/Modules/Scripted/SegmentStatistics/SegmentStatistics.py) (here the inheritance happens on the module widget level)
- [https://github.com/Slicer/Slicer/blob/master/Modules/Scripted/DICOMLib/DICOMWidgets.py](https://github.com/Slicer/Slicer/blob/master/Modules/Scripted/DICOMLib/DICOMWidgets.py)
