How to create a drop down list with multiple options

How do I create a drop-down list with multiple options and each option onclick performs a different function? I am trying to do this in python for a module.

This is hardly a Slicer question, but my suggestion would be to use a QMenu and populate it with QActions. If you search in the Slicer source code you will find plenty of examples.

1 Like

Sorry. I understand the irrelevance.

I have been trying to create this drop-down list to add a certain functionality to my module, specifically just have 2 to 3 options to perform addition or subtraction of segments. I have created the drop-down list using qt and created a UI for a combo box. But I don’t understand how to add a onclick function to the options in the drop-down list. If anyone has implemented anything similar please let me know. Thank you.

I would suggest to review the QComboBox documentation as it relates to Signals. QComboBox Class | Qt Widgets 5.15.3

The currentIndexChanged or even the activated signal would allow you to link to a selection changed or selected event respectively.

Although it is possible to use a combobox like this, let me give my 2 cents in that using a combobox to directly run functions is not a good design choice. Such widgets are used to make selections, so it would be legit if you had an Apply button below the combobox that gets the current selection and runs the proper function. Or as an alternative you can use a menu, or a series of buttons or tool buttons.