# qMRMLSubjectHierarchyComboBox usage

**URL:** <https://discourse.slicer.org/t/qmrmlsubjecthierarchycombobox-usage/763>\
**Category:** Development\
**Created:** [July 25, 2017, 5:06pm UTC](https://discourse.slicer.org/t/qmrmlsubjecthierarchycombobox-usage/763 "2017-07-25T17:06:06Z")\
**Posts on this page:** 18\
**Page:** 2

<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:** [August 4, 2017, 8:35pm UTC](https://discourse.slicer.org/t/qmrmlsubjecthierarchycombobox-usage/763/21 "2017-08-04T20:35:56Z")

</div>

Is adding a module to the Slicer source code itself the way to go for examples like this? I could imagine a variety of ways that are simpler than building a whole Slicer from scratch.

---

<div class="post-metadata">

**Author:** ![dzenanz](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/dzenanz/32/1992_2.png) [@dzenanz](https://discourse.slicer.org/u/dzenanz)\
**Post date:** [August 7, 2017, 4:41pm UTC](https://discourse.slicer.org/t/qmrmlsubjecthierarchycombobox-usage/763/22 "2017-08-07T16:41:07Z")

</div>

I don’t know why my code isn’t working, so keeping its build system might be important. Also rewriting it into a copy-paste script would have required a lot of effort. I know that building Slicer is slow, but it does not require much effort. A faster way to test this is to copy-paste added files (and the modified CMakeLists) into existing Slicer instance and rebuilding it.

---

<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:** [August 7, 2017, 9:24pm UTC](https://discourse.slicer.org/t/qmrmlsubjecthierarchycombobox-usage/763/23 "2017-08-07T21:24:27Z")

</div>

I built your branch, and did the following:

- Uncomment line 18
- Start Slicer
- Load MRHead (so that there is one node that has no attributes)
- Load a CT and an RTDOSE from DICOM
- Switch to your module

The combobox was not empty and I only saw the CT, which is the expected behaviour. Did I do something in a different order than the way you could reproduce it?

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [August 7, 2017, 10:46pm UTC](https://discourse.slicer.org/t/qmrmlsubjecthierarchycombobox-usage/763/24 "2017-08-07T22:46:24Z")

</div>

@dzenanz Let’s work together and offline to address the issue. We can then report back our findings.

@cpinter Thanks for looking into the problem.

---

<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:** [August 7, 2017, 11:04pm UTC](https://discourse.slicer.org/t/qmrmlsubjecthierarchycombobox-usage/763/25 "2017-08-07T23:04:19Z")

</div>

In case you want to do some debugging, a breakpoint here should help revealing the problem:

> <https://github.com/Slicer/Slicer/blob/master/Modules/Loadable/SubjectHierarchy/Widgets/qMRMLSortFilterSubjectHierarchyProxyModel.cxx#L335>

---

<div class="post-metadata">

**Author:** ![dzenanz](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/dzenanz/32/1992_2.png) [@dzenanz](https://discourse.slicer.org/u/dzenanz)\
**Post date:** [August 8, 2017, 2:47pm UTC](https://discourse.slicer.org/t/qmrmlsubjecthierarchycombobox-usage/763/26 "2017-08-08T14:47:20Z")

</div>

@lassoan You were right about order of widget creation and data loading. Loading data first, and then accessing the widget works (but not the other way around). But I think I tested that - I guess not carefully enough.

@cpinter Do you have some suggestion for `currentItemChanged` not firing?

---

<div class="post-metadata">

**Author:** ![dzenanz](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/dzenanz/32/1992_2.png) [@dzenanz](https://discourse.slicer.org/u/dzenanz)\
**Post date:** [August 8, 2017, 2:49pm UTC](https://discourse.slicer.org/t/qmrmlsubjecthierarchycombobox-usage/763/27 "2017-08-08T14:49:03Z")

</div>

I am taking rest of the day off, so I could debug this tomorrow (unless you beat me to it). But it is probably due to some scene change event not being observed, and not in the logic here.

---

<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:** [August 8, 2017, 4:33pm UTC](https://discourse.slicer.org/t/qmrmlsubjecthierarchycombobox-usage/763/28 "2017-08-08T16:33:48Z")

</div>

You probably use currentItemChanged wrong. It works in this example. Please look at the differences. As a last resort you can just copy-paste the related code

> <https://github.com/SlicerRt/SegmentRegistration/blob/master/ProstateMRIUSContourPropagation/ProstateMRIUSContourPropagation.py#L72>

---

<div class="post-metadata">

**Author:** ![dzenanz](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/dzenanz/32/1992_2.png) [@dzenanz](https://discourse.slicer.org/u/dzenanz)\
**Post date:** [August 9, 2017, 3:56pm UTC](https://discourse.slicer.org/t/qmrmlsubjecthierarchycombobox-usage/763/29 "2017-08-09T15:56:50Z")

</div>

I tried that. Now I added that to MWE. The event is still not triggered.  
[https://github.com/dzenanz/Slicer/commit/7335435f49a8946badba9dbfa90dbb7d9bca6871](https://github.com/dzenanz/Slicer/commit/7335435f49a8946badba9dbfa90dbb7d9bca6871)

---

<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:** [August 9, 2017, 4:26pm UTC](https://discourse.slicer.org/t/qmrmlsubjecthierarchycombobox-usage/763/30 "2017-08-09T16:26:29Z")

</div>

I don’t know what to add. I provided a working example, which still works. Please try to find the difference that makes yours inoperational.

---

<div class="post-metadata">

**Author:** ![dzenanz](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/dzenanz/32/1992_2.png) [@dzenanz](https://discourse.slicer.org/u/dzenanz)\
**Post date:** [August 9, 2017, 5:25pm UTC](https://discourse.slicer.org/t/qmrmlsubjecthierarchycombobox-usage/763/31 "2017-08-09T17:25:06Z")

</div>

The only big difference is that in [ProstateMRIUSContourPropagation](https://github.com/SlicerRt/SegmentRegistration/blob/master/ProstateMRIUSContourPropagation/ProstateMRIUSContourPropagation.py#L72) UI is generated programatically, whereas in my MWE it is loaded from a `.ui` file using `QUiLoader`.

---

<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:** [August 9, 2017, 5:40pm UTC](https://discourse.slicer.org/t/qmrmlsubjecthierarchycombobox-usage/763/32 "2017-08-09T17:40:14Z")

</div>

If that is the only difference then is it possible that the widget is not completely set up by the time you try to connect?

---

<div class="post-metadata">

**Author:** ![dzenanz](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/dzenanz/32/1992_2.png) [@dzenanz](https://discourse.slicer.org/u/dzenanz)\
**Post date:** [August 9, 2017, 6:05pm UTC](https://discourse.slicer.org/t/qmrmlsubjecthierarchycombobox-usage/763/33 "2017-08-09T18:05:24Z")

</div>

That [does not](https://github.com/dzenanz/Slicer/commit/3670a645d64ef94a37548643224936a185c4b15f) seem to matter. Even if if the only thing left to do are connections, connecting `currentItemChanged` has no effect.

---

<div class="post-metadata">

**Author:** ![dzenanz](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/dzenanz/32/1992_2.png) [@dzenanz](https://discourse.slicer.org/u/dzenanz)\
**Post date:** [August 17, 2017, 5:38pm UTC](https://discourse.slicer.org/t/qmrmlsubjecthierarchycombobox-usage/763/34 "2017-08-17T17:38:27Z")

</div>

In an attempt to get a working MWE, I tried starting from the existing module. However the event does not fire in it either!

> <https://github.com/dzenanz/Slicer/blob/915dcd08afa3dcdee5e78a322b83850833ffac12/Modules/Scripted/ProstateMRIUSContourPropagation/ProstateMRIUSContourPropagation.py#L236>

---

<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:** [August 17, 2017, 5:50pm UTC](https://discourse.slicer.org/t/qmrmlsubjecthierarchycombobox-usage/763/35 "2017-08-17T17:50:22Z")

</div>

Thanks, @dzenanz! This is strange indeed, I’ll investigate at once, as it’s very easy for me to reproduce now.

---

<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:** [August 22, 2017, 7:24pm UTC](https://discourse.slicer.org/t/qmrmlsubjecthierarchycombobox-usage/763/36 "2017-08-22T19:24:41Z")

</div>

Hi @dzenanz, sorry for the wait! The cause of the problem was very banal: the signal was not propagated to the combobox (aggregation vs inheritance…). I committed a fix in Slicer. Please let me know how it works.

> <https://github.com/Slicer/Slicer/commit/b9acab728f0a44841cfc2c039a7fd2a419025eed>

---

<div class="post-metadata">

**Author:** ![dzenanz](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/dzenanz/32/1992_2.png) [@dzenanz](https://discourse.slicer.org/u/dzenanz)\
**Post date:** [August 22, 2017, 11:15pm UTC](https://discourse.slicer.org/t/qmrmlsubjecthierarchycombobox-usage/763/37 "2017-08-22T23:15:26Z")

</div>

Thanks Csaba, that seems to have fixed it!

---

<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:** [August 23, 2017, 1:05pm UTC](https://discourse.slicer.org/t/qmrmlsubjecthierarchycombobox-usage/763/38 "2017-08-23T13:05:50Z")

</div>

Excellent! Sorry for giving you a hard time, I was fully in the knowledge that the function in MRI-US worked.

[Previous page](https://discourse.slicer.org/t/qmrmlsubjecthierarchycombobox-usage/763.md?page=1)
