[PyQt] qcombobox SIGNAL issue

Lorenzo Bernardi lorenzo.bernardi at lpn.cnrs.fr
Wed Jun 11 14:08:35 BST 2014


On 06/11/2014 02:41 PM, singhai.nish wrote:
> As seen in image, I need that when user changes values in 1st combo, that 2nd
> combo displays another list
> So, when 2nd changes that 3rd combobox displays another set.
>
> At present what is happening is that when 1st is changed, 2nd and 3rd both
> get changed. ( only 2nd should be changed ).
you wrote
         QtCore.QObject.connect(self.comboBox, 
QtCore.SIGNAL("currentIndexChanged(int)"), self.abcdef)
         QtCore.QObject.connect(self.comboBox_2, 
QtCore.SIGNAL("currentIndexChanged(int)"), self.ghhijkl)

which means that when you change the current index of self.comboBox it 
execute self.abcdef which change the currentindex of combobox2 which in 
turns according to the second connect execute self.ghhijkl and thus 
change comboBox3


>
> How to ensure that only one signal works on one combobox ( as this is how it
> is designed ).
Since your flow is to activate the first combobox to set a value to the 
second combobox I would set the combobox three to a state compatible to 
the second combobox. I mean it looks like the combobox three is set from 
the combobox 2 values and since you set it via the combobox one

as an exemple I will take
country state city

when you select a country the first state in the list of the state of 
the country  should be set and the first city of the list of the city of 
the state should appear

Otherwise setting a self.calledFromCombobox1 = True and then unsetting 
it but I think it is not a good idea since you are going against the 
logic of Qt (IMHO)
> What am i missing.?
That changing current index can be done programmaticaly or via the GUI 
but both triggers the QtCore.QObject.connect

L.


More information about the PyQt mailing list