# How to select a qComboBox programmatically in Simple Filters module

**URL:** <https://discourse.slicer.org/t/how-to-select-a-qcombobox-programmatically-in-simple-filters-module/28329>\
**Category:** Support\
**Tags:** python\
**Created:** [March 12, 2023, 3:26pm UTC](https://discourse.slicer.org/t/how-to-select-a-qcombobox-programmatically-in-simple-filters-module/28329 "2023-03-12T15:26:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![WilliamLambert1205](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/williamlambert1205/32/16334_2.png) [@WilliamLambert1205](https://discourse.slicer.org/u/WilliamLambert1205)\
**Post date:** [March 12, 2023, 3:26pm UTC](https://discourse.slicer.org/t/how-to-select-a-qcombobox-programmatically-in-simple-filters-module/28329/1 "2023-03-12T15:26:57Z")

</div>

Hi,everyone. I’m trying to using code to substitute a series of mouse clicking and I get into trouble, please guide me.  
In the first step, I need to select the first item in ‘OutputVolume’.(‘OutputVolume’ is a qComboBox).  
In the second step, I need to select another, it means the second item in ‘OutputVolume’.

The apperance of this problem is when I click every qComboBox and select, every thing goes right, however, when I set the qComboBox programmly, it seems like I haven’t changed the ‘OutputVolume’ though the words showed is changed. And the result by program is same as when I only do the first step by clicking, but skip the second step.

I guess the problem is, in the second step, these 2 lines below,

```auto
OutputVolume=SimpleFiltersWidgetWhole[7]
OutputVolume.setCurrentNodeIndex(1)

```

which seems to only change what is showed visually in the qComboBox, but don’t truely get the item selected. In other word, it seems I need one more ‘click’ on the item to get it selected.

I loaded 2 .nii as volume.Hi,everyone. I’m trying to using code to substitute a series of mouse clicking and I get into trouble, please guide me.  
In the first step, I need to select the first item in ‘OutputVolume’.(‘OutputVolume’ is a qComboBox).  
In the second step, I need to select another, it means the second item in ‘OutputVolume’.

The apperance of this problem is when I click every qComboBox and select, every thing goes right, however, when I set the qComboBox programmly, it seems like I haven’t changed the ‘OutputVolume’ though the words showed is changed. And the result by program is same as when I only do the first step by clicking, but skip the second step.

I guess the problem is, in the second step, these 2 lines below,  
OutputVolume=SimpleFiltersWidgetWhole[7]  
OutputVolume.setCurrentNodeIndex(1)  
which seems to only change what is showed visually in the qComboBox, but don’t truely get the item selected. In other word, it seems I need one more ‘click’ on the item to get it selected.

I loaded 2 .nii as volume.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/d/3/d3186fbcec9c92df20c070013d753e8a61016297.png)  
my code below

```auto
#First flip
slicer.modules.simplefilters.widgetRepresentation()
slicer.modules.SimpleFiltersWidget.searchBox.setText(‘FlipImageFilter’)
SimpleFiltersWidgetWhole=slicer.modules.SimpleFiltersWidget.filterParameters.widgets
InputVolume=SimpleFiltersWidgetWhole[0]
InputVolume.setCurrentNodeIndex(0)
FlipAxesSpinbox1=FlipAxesSpinbox[1]#SagittalplaneFlip
FlipAxesSpinbox1.setValue(1)
FlipAxesSpinbox2=FlipAxesSpinbox[2]#CoronalplaneFlip
FlipAxesSpinbox2.setValue(0)
FlipAxesSpinbox3=FlipAxesSpinbox[3]#HorizontalplaneFlip
FlipAxesSpinbox3.setValue(0)
#setFlipAboutOriginchecked
FlipAboutOrigin=SimpleFiltersWidgetWhole[4]
FlipAboutOrigin.setChecked(1)
#setLabelMapchecked

LabelMap=SimpleFiltersWidgetWhole[9]
LabelMap.setChecked(0)
slicer.modules.SimpleFiltersWidget.applyButton.clicked()

#Secondflip
InputVolume=SimpleFiltersWidgetWhole[0]
InputVolume.setCurrentNodeIndex(1)
OutputVolume=SimpleFiltersWidgetWhole[7]
OutputVolume.setCurrentNodeIndex(1)
FlipAxes=SimpleFiltersWidgetWhole[2]#FlipAxes
FlipAxes.coordinates
FlipAxes.children()
FlipAxesSpinbox=FlipAxes.children()

FlipAxesSpinbox1=FlipAxesSpinbox[1]#SagittalplaneFlip
FlipAxesSpinbox1.setValue(1)
FlipAxesSpinbox2=FlipAxesSpinbox[2]#CoronalplaneFlip
FlipAxesSpinbox2.setValue(0)
FlipAxesSpinbox3=FlipAxesSpinbox[3]#HorizontalplaneFlip
FlipAxesSpinbox3.setValue(0)

#setFlipAboutOriginchecked

FlipAboutOrigin=SimpleFiltersWidgetWhole[4]

FlipAboutOrigin.setChecked(1)
#setLabelMapchecked
LabelMap=SimpleFiltersWidgetWhole[9]
LabelMap.setChecked(1)

slicer.modules.SimpleFiltersWidget.applyButton.clicked()

```

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [March 12, 2023, 3:45pm UTC](https://discourse.slicer.org/t/how-to-select-a-qcombobox-programmatically-in-simple-filters-module/28329/2 "2023-03-12T15:45:30Z")

</div>

Rather than trying to script the GUI, you could just use the SimpleITK code directly:

[https://slicer.readthedocs.io/en/latest/developer\_guide/script\_repository.html#running-an-itk-filter-in-python-using-simpleitk](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#running-an-itk-filter-in-python-using-simpleitk)
