GUI widget to select a file

I am creating a module where I need to import an H5 file, process it and then display it to the output node. How do I get the option to view a dialogue box so that I can select a file?

I found an example in the SlicerITKUltrasound, ScanConvertSliceSeries module, But could not understand how to script it in python.


That is the ctkPathLineEdit widget. See a gallery of more CTK widgets here. If you use scripteddesigner template when you create your scripted module then you can use Qt designer to create your GUI. All the available widgets are shown there and you can simply drag-and-drop them to your module GUI:

See step-by-step tutorial here.

Hi Andras,
I am using scripteddesigner. I can drag and drop and create easily the designer but how can i connect the components in the script. for example if I added ctkpathlineedit. how can i add it in the script and how can i use it.

I now how to use the other filters the input mrmrl selector and buttons but i am unable to see how to use this one.

Thank you in advance.

Saima Safdar

Hi Andras,
I added the ctk widgets(collapsible button and pathlineedit) using qt designer but when I load the example in 3d slicer. it doesnt show me pathlineedit inside the ctk collapsible button. It only shows ctkcollapsible buttons.

If I use below lines it will create new collapsible buttons and pathline edits but I want to use the pathline edit created from the qt designer.
parametersCollapsibleButton = ctk.ctkCollapsibleButton()
parametersCollapsibleButton.text = “Parameters”

# Layout within the dummy collapsible button
parametersFormLayout = qt.QFormLayout(parametersCollapsibleButton)

self.inputDirSelector = ctk.ctkPathLineEdit()
self.inputDirSelector.filters = ctk.ctkPathLineEdit.Dirs
self.inputDirSelector.settingKey = 'DICOMPatcherInputDir'
parametersFormLayout.addRow("Input DICOM directory:", self.inputDirSelector)

Thank you

Saima Safdar

Without seeing your .ui file I can only guess. After you drag-and-drop a widget into a collapsible button, you need to set the layout for the collapsible button. Maybe you have missed that step.

If you can send a link to your module then I can have a look.

Hi Andras,
I am sending the link to the module. I added model collapsible button using qt designer and the checkbox as well when I open module in slicer it doesnt show me the content inside collapsible button.

Everything looks good to me:

If I drag-and-drop a ctkPathLineEdit widget to the GUI layout in QtDesigner and click Reload in Slicer then the widget shows up correctly in the module GUI in Slicer.

I would recommend to remove code from the .py file that creates widgets and instead add all widgets to the .ui file.

1 Like

Yes it worked now. Do we need the vertical height of collapsible to be fixed.