[PyQt] qcombobox SIGNAL issue

Baz Walter bazwal at ftml.net
Wed Jun 11 14:47:15 BST 2014


On 11/06/14 14:31, singhai.nish wrote:
> This was an example. My bad, actually I need that when user selects one from
> combobox, that based on that selection a list is displayed in combobox_2,
> then based on selection in combobox_2, a list should be displayed in
> combobox_3
>

Don't use currentIndexChanged, use the activated signal instead:

     https://qt-project.org/doc/qt-4.8/qcombobox.html#activated

This will only fire when the *user* changes an item in the combo box, 
and so the signals won't trigger each other.

Your example also has a few other issues. A better way to write it would 
be something like this:

         self.comboBox.activated[str].connect(self.abcdef)
         self.comboBox_2.activated[str].connect(self.ghijkl)
         ...

     def abcdef(self, text):
         print "in abcdef ...", text
         if text == "1":
             self.comboBox_2.setCurrentIndex(1)
         elif text == "3":
             self.comboBox_2.setCurrentIndex(0)
         elif text == "2":
             self.comboBox_2.setCurrentIndex(2)

(Note the zero-based indexing).

-- 
Regards
Baz Walter


More information about the PyQt mailing list