I am developing a new qSlicerWidget that should be shown when a button that is part of a qMRMLWidget is clicked. When the new qSlicerWidget is created empty, it is possible to see the new window without any elements inside.
But when I try to load a UI created from qtStudio in a UI file that contains a widget. The class is in a new file as shown below:
import slicer
import os
class TutorialGUI(slicer.qSlicerWidget):
def __init__(self, parent=None):
super().__init__(parent)
print(self)
dir_path = os.path.dirname(__file__)
self.Widget = slicer.util.loadUI(dir_path+'/../Resources/UI/TutorialGUI.ui')
self.layout.addWidget(self.Widget)
def showEvent(self, event):
# Do something when the window is shown
print("The window is shown!")
in python console shows following error message:
Traceback (most recent call last):
File "/Users/victormontanoserrano/Documents/3DSlicer/NewGui/NewGUI/NewGUI.py", line 141, in __init__
self.window = TutorialGUI()
File "/Users/victormontanoserrano/Documents/3DSlicer/NewGui/NewGUI/Lib/TutorialGUI.py", line 11, in __init__
self.layout.addWidget(self.Widget)
AttributeError: 'builtin_qt_slot' object has no attribute 'addWidget'
[Qt] qSlicerPythonCppAPI::instantiateClass - [ "NewGUIWidget" ] - Failed to instantiate scripted pythonqt class "NewGUIWidget" 0x7fcbb551fba0