apparrilla
(Angel R Piñera)
November 1, 2020, 10:12am
1
Hi!
I want to customize a SubjectHierarchyTreeView Widget in a module.
Things to change:
self.uit.SubjectHierarchyTreeView.nodeTypes = [“vtkMRMLModelNode”]
Change header text: “Node” → “Model”
Hide columns: “ID”, “color”
Change colums order: Put View/Hide first one
Add new columns: should be lovely to add an “Opacity slider”, something like Segementations Module one.
Slicer ver: 4.11.20200930 r29402 / 002be18
OS: Win10
Thanks on advace!
cpinter
(Csaba Pinter)
November 1, 2020, 9:08pm
2
subjectHierarchyTreeView.setColumnHidden(subjectHierarchyTreeView.model().idColumn, True)
subjectHierarchyTreeView.setColumnHidden(subjectHierarchyTreeView.model().colorColumn, True)
Probably something like this:
subjectHierarchyTreeView.model().setHorizontalHeaderLabels(['Models', ...])
apparrilla:
Change colums order
I believe you can do it by calling functions like setNameColumn
with the desired column index.
apparrilla:
Add new columns
I’m afraid for this you’ll need to extend or subclass the qMRMLSubjectHierarchyModel class.
1 Like
apparrilla
(Angel R Piñera)
November 3, 2020, 11:44pm
3
Hi @cpinter !
Thanks to your answare, I´ve able to get this result:
This is my code:
self.ui.SubjectHierarchyTreeView.nodeTypes = [“vtkMRMLModelNode”]
self.ui.SubjectHierarchyTreeView.setColumnHidden(self.uit.SubjectHierarchyTreeView.model().idColumn, True)
self.ui.SubjectHierarchyTreeView.setColumnHidden(self.uit.SubjectHierarchyTreeView.model().colorColumn, True)
self.ui.SubjectHierarchyTreeView.setColumnHidden(self.uit.SubjectHierarchyTreeView.model().transformColumn, True)
self.ui.SubjectHierarchyTreeView.model().setHorizontalHeaderLabels([‘Models’, …])
self.ui.SubjectHierarchyTreeView.setMRMLScene( slicer.mrmlScene )
I havent been able to change columns order after many attempts with different methods from qMRMLSubjectHierarchyTreeView Class and qMRMLSubjectHierarchyModel documentation.
Thank you very much for your help!
lassoan
(Andras Lasso)
November 3, 2020, 11:56pm
4
You can show/hide and change the order of columns by specifying colorColumn, descriptionColumn, etc. values. See documentation .
apparrilla
(Angel R Piñera)
November 4, 2020, 12:46am
5
Sorry @lassoan . I don´t know how to do it…
Error message:
line 200, in setup self.ui.SubjectHierarchyTreeView.model().setVisibilityColumn(0)
AttributeError: qMRMLSubjectHierarchyModel has no attribute named ‘setVisibilityColumn’
lassoan
(Andras Lasso)
November 4, 2020, 2:23am
6
colorColumn
is a property. You can set it as:
self.ui.SubjectHierarchyTreeView.model().visibilityColumn = 0
This documentation page can help in interpreting the API documentation: https://slicer.readthedocs.io/en/latest/developer_guide/api.html#doxygen-style-documentation
1 Like
apparrilla
(Angel R Piñera)
November 4, 2020, 2:49pm
7
I´ve triyed:
self.uit.SubjectHierarchyTreeView.model().visibilityColumn = 0
self.uit.SubjectHierarchyTreeView.model().nameColumn = 1
self.uit.SubjectHierarchyTreeView.model().descriptionColumn = 2
But result is the same:
Sorry to waste your precious time…!
lassoan
(Andras Lasso)
November 4, 2020, 6:48pm
8
It works for me. Note that you need to change the headers label and icons with a separate call (it could be nice if that was updated automatically, if you have time to implement this then a pull request would be welcome):
tv=slicer.qMRMLSubjectHierarchyTreeView()
tv.model().visibilityColumn=3
tv.model().colorColumn=2
tv.setMRMLScene(slicer.mrmlScene)
tv.model().setHorizontalHeaderLabels(['a','b','c','d','e','f'])
tv.show()
1 Like
apparrilla
(Angel R Piñera)
November 4, 2020, 10:13pm
9
Ok. My problem was the headers order and columns width. Items reorder in new columns distribution but but headers stay in original order.
I´d like to help but it´s too much for my current poor code skills…
Thanks to all.