There are a couple ways to do this. One is to store your callbacks as the
data for each item:

class Test(QtGui.QDialog):

    def __init__(self):
        super(Test, self).__init__()

        self.combo = QtGui.QComboBox()
        self.combo.addItem("First Callback", self.callback1)
        self.combo.addItem("Second Callback", self.callback2)

        self.combo.activated.connect(self._comboActivated)

        layout = QtGui.QVBoxLayout(self)
        layout.addWidget(self.combo)

    def callback1(self):
        print "callback1"

    def callback2(self):
        print "callback2"

    def _comboActivated(self, idx):
        fn = self.combo.itemData(idx)
        fn()

​


On Fri, Oct 10, 2014 at 11:12 PM, Marcus Ottosson <[email protected]>
wrote:

> Have look at the currentIndexChanged signal.
> http://qt-project.org/doc/qt-4.8/qcombobox.html#signals
>
> On 10 October 2014 11:02, likage <[email protected]> wrote:
>
>> I have a QComboBox in which it contains 2 items.
>>
>> How can I code it in such a way that when the first item in the combobox
>> is selected, it will call out the function that is for the first item.
>> Likewise, if the second item is selected, it will call out the function for
>> the second item, something similar like using list index [0], [1] etc..
>>
>> self.methodCombo = QComboBox()
>> self.methodCombo.addItem('method01')
>> self.methodCombo.addItem('method02')
>>
>>
>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Python Programming for Autodesk Maya" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/python_inside_maya/6c1e4e7e-74e4-4976-b7a5-f6cfa252016a%40googlegroups.com
>> <https://groups.google.com/d/msgid/python_inside_maya/6c1e4e7e-74e4-4976-b7a5-f6cfa252016a%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> *Marcus Ottosson*
> [email protected]
>
> --
> You received this message because you are subscribed to the Google Groups
> "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOC1AzRyoV7f-tdpxTG-8K9CcvnBsdKRp6PoWubBNaXf-A%40mail.gmail.com
> <https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOC1AzRyoV7f-tdpxTG-8K9CcvnBsdKRp6PoWubBNaXf-A%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA25-VXx%3D9N6EYCMsp8Uj6ypNAh-ZJtr%2B%3DXz8KYDQ48XVw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to