pll_llq
(Theodore Aptekarev)
February 24, 2021, 1:17pm
1
Hi
I want to display a widget that will takes the space used by the view layout.
As I understand after reading reply to this post I can’t have a QMRMLWidget as a part of a custom layout.
I tried to manually set my widget to be the centralWidget
of the mainWindow
with
mainWindow = slicer.util.mainWindow()
mainWindow.setCentralWidget(mywidget)
and I see the result, but the existing layout manager get’s destroyed.
So when I try to revert to a view layout I am met with an error:
ValueError: Trying to call 'setLayout' on a destroyed qSlicerLayoutManager object
Here’s the sample code . Copy-paste into Slicer python interpreter works.
I guess that setting the centralWidget like that is not a good idea. Can anyone advice how to correctly show my widget in the middle of the main window?
lassoan
(Andras Lasso)
February 24, 2021, 1:37pm
2
Custom widgets are placed inside the view layout. The simplest way is to use qSlicerSingletonViewFactory
as it is done in the DICOM module.
1 Like
pll_llq
(Theodore Aptekarev)
February 24, 2021, 1:39pm
3
Thanks, this something that I wanted to try.
pll_llq
(Theodore Aptekarev)
February 24, 2021, 4:24pm
4
Thanks, it worked.
I’ve added
viewFactory = slicer.qSlicerSingletonViewFactory()
viewFactory.setWidget(mywidget)
viewFactory.setTagName("helloLayout")
layoutManager.registerViewFactory(viewFactory)
layout = (
"<layout type=\"horizontal\">"
" <item>"
" <helloLayout></helloLayout>"
" </item>"
"</layout>"
)
customLayoutId = 42
layoutNode = slicer.app.layoutManager().layoutLogic().GetLayoutNode()
layoutNode.AddLayoutDescription(customLayoutId, layout)
layoutManager.setLayout(customLayoutId)
instead of manipulating the centralWidget and got a nice layout with my widget.
1 Like