If current text/index is change in combobox
-
Hi,
I have problem to find the if-statement to recognise if combobox was change to a different value.
My plan is that: the user change the index (and text in this function) in one combobox (either in 9th or in 10th), and automatically change the index in 2nd combox to the same number.
Current code you see below. The 2nd if-statement line doesn't work. I don't know what to put in event class (text error: not enough arguments)
when I tried version from the last if-statement gains error: 'native Qt signal is not callable' ('kod' come from: self.dlg.comboBox_10.currentText())
if self.dlg.comboBox_9.currentIndex() != self.dlg.comboBox_10.currentIndex():#if indexes are different: if self.dlg.comboBox_9.event():#signal that in this combox text and index was changed (now is not enough arguments) self.dlg.comboBox_10.currentTextChanged.connect(self.wybPow)#start the function that set equivalent index in the 2nd combobox if self.dlg.comboBox_10.currentTextChanged(kod): #another version- also doesn't work - 2 error self.dlg.comboBox_9.currentTextChanged.connect(self.wybTer)#same as first but in the opposite combobox
thanks for every kind of help
PS. If you lose patient to me like was last time hire in this forum I say one: This is the last think (but very important) to do in my qt app before the general testing
-
Hi,
I have problem to find the if-statement to recognise if combobox was change to a different value.
My plan is that: the user change the index (and text in this function) in one combobox (either in 9th or in 10th), and automatically change the index in 2nd combox to the same number.
Current code you see below. The 2nd if-statement line doesn't work. I don't know what to put in event class (text error: not enough arguments)
when I tried version from the last if-statement gains error: 'native Qt signal is not callable' ('kod' come from: self.dlg.comboBox_10.currentText())
if self.dlg.comboBox_9.currentIndex() != self.dlg.comboBox_10.currentIndex():#if indexes are different: if self.dlg.comboBox_9.event():#signal that in this combox text and index was changed (now is not enough arguments) self.dlg.comboBox_10.currentTextChanged.connect(self.wybPow)#start the function that set equivalent index in the 2nd combobox if self.dlg.comboBox_10.currentTextChanged(kod): #another version- also doesn't work - 2 error self.dlg.comboBox_9.currentTextChanged.connect(self.wybTer)#same as first but in the opposite combobox
thanks for every kind of help
PS. If you lose patient to me like was last time hire in this forum I say one: This is the last think (but very important) to do in my qt app before the general testing
@Karoluss96 Isn't it as simple as:
self.dlg.comboBox_10.currentIndexChanged.connect(self.dlg.comboBox_2.setCurrentIndex)
?
-
@jsulm said in If current text/index is change in combobox:
self.dlg.comboBox_10.current
instead of all lines, or like now:
if self.dlg.comboBox_9.currentIndex() != self.dlg.comboBox_10.currentIndex(): if self.dlg.comboBox_10.currentIndexChanged.connect(self.dlg.comboBox_9.setCurrentIndex): self.dlg.comboBox_10.currentTextChanged.connect(self.wybPow) if self.dlg.comboBox_9.currentIndexChanged.connect(self.dlg.comboBox_10.setCurrentIndex): self.dlg.comboBox_9.currentTextChanged.connect(self.wybTer)
-
@jsulm said in If current text/index is change in combobox:
self.dlg.comboBox_10.current
instead of all lines, or like now:
if self.dlg.comboBox_9.currentIndex() != self.dlg.comboBox_10.currentIndex(): if self.dlg.comboBox_10.currentIndexChanged.connect(self.dlg.comboBox_9.setCurrentIndex): self.dlg.comboBox_10.currentTextChanged.connect(self.wybPow) if self.dlg.comboBox_9.currentIndexChanged.connect(self.dlg.comboBox_10.setCurrentIndex): self.dlg.comboBox_9.currentTextChanged.connect(self.wybTer)
@Karoluss96 If I understood you correctly (your description is not very clear) you want to change the index of your second combo box to the same index as in combo box 10 or 9 as soon as the user selects something in one of them, is that right? If so, then
self.dlg.comboBox_9.currentIndexChanged.connect(self.dlg.comboBox_2.setCurrentIndex) self.dlg.comboBox_10.currentIndexChanged.connect(self.dlg.comboBox_2.setCurrentIndex)
-
so close, but if-statements must be (in my point of view), because user can change the value/index EITHER in combobox_9 OR in combobox_10.
The user himself decide from which combobox will choose the interesting value and automatically change the value in the 2nd one (if indexes are different the won't any results in later sql query)
So in pseudocode:
if combobox_10 (text/index) is changed:
index in combobox_9 must set to equivalent number as in in 10
if combobox_9 (text/index) is changed:
index in combobox_10 must set to equivalent number as in in 9 -
so close, but if-statements must be (in my point of view), because user can change the value/index EITHER in combobox_9 OR in combobox_10.
The user himself decide from which combobox will choose the interesting value and automatically change the value in the 2nd one (if indexes are different the won't any results in later sql query)
So in pseudocode:
if combobox_10 (text/index) is changed:
index in combobox_9 must set to equivalent number as in in 10
if combobox_9 (text/index) is changed:
index in combobox_10 must set to equivalent number as in in 9@Karoluss96 said in If current text/index is change in combobox:
because user can change the value/index EITHER in combobox_9 OR in combobox_10.
I don't see the need for if. User selects either combobox 10 or 9, right? User can't select both at the same time. So, why would you need if?
-
@jsulm said in If current text/index is change in combobox:
don't see the need for if. User selects either combobox 10 or 9, right? User can't select both at the same time. So, why would you need if?
Ok in another way (with picture). One combobox shows the powiat (Polish's 2nd Adminstrative unions lavel- lake Countries in States in USA), 2nd the geografical code of it (call it TERYT).
I made a sql query that shows the result of seaching results where user can choose either or both 2 values.If geografical code of selected admin unit is different than his name (or vice versa) there's no results.
The name of correct powiat (or his geografical TERYT code) must immidately change to current to avoid empty record and user needn't to correct 2nd value manually
Finally my CEO want to make that!
And yes: the user can't change it in the same time both!
-
@jsulm said in If current text/index is change in combobox:
don't see the need for if. User selects either combobox 10 or 9, right? User can't select both at the same time. So, why would you need if?
Ok in another way (with picture). One combobox shows the powiat (Polish's 2nd Adminstrative unions lavel- lake Countries in States in USA), 2nd the geografical code of it (call it TERYT).
I made a sql query that shows the result of seaching results where user can choose either or both 2 values.If geografical code of selected admin unit is different than his name (or vice versa) there's no results.
The name of correct powiat (or his geografical TERYT code) must immidately change to current to avoid empty record and user needn't to correct 2nd value manually
Finally my CEO want to make that!
And yes: the user can't change it in the same time both!
@Karoluss96 If you need to use if then change your code - it makes no sense as it is now. You need to connect a slot to currentIndexChanged signal of both (10 and 9) combo boxes. In that slot you can then check your conditions to decide what to do.
self.dlg.comboBox_9.currentTextChanged.connect(self.indexChanged) self.dlg.comboBox_10.currentTextChanged.connect(self.indexChanged) def indexChanged(self): if ...
-
OK, but what to put in if-statement (to connect 2 functions in one)?
The code for indexChanged for powiat/TERYT looks that:
query = QSqlQuery(db)#db = QSqlDatabase.addDatabase("QOCISPATIAL") powiat = self.dlg.comboBox_9.currentText()#eg..boleslawiecki poInd = self.dlg.comboBox_9.currentIndex()#eg. 0 print (poInd) # 0 kod = self.dlg.comboBox_10.currentText()# eg. 0201 sqlP = 'SELECT TERYT FROM ZARZADZANIE.POWIATY WHERE powiat_nazwa = \'' + powiat + '\'' query.exec_(sqlP) while query.next(): powiat = query.record().value(0) print (powiat)# boleslawiecki q=self.dlg.comboBox_10.findText(powiat) print (q)#0 #self.dlg.comboBox_10.setItemText(q,powiat) #self.dlg.comboBox_10.setCurrentIndex(poInd) self.dlg.comboBox_10.setCurrentIndex(q)
The secod one have only 10 and 9 replace (and a little sql text)
-
so close, but if-statements must be (in my point of view), because user can change the value/index EITHER in combobox_9 OR in combobox_10.
The user himself decide from which combobox will choose the interesting value and automatically change the value in the 2nd one (if indexes are different the won't any results in later sql query)
So in pseudocode:
if combobox_10 (text/index) is changed:
index in combobox_9 must set to equivalent number as in in 10
if combobox_9 (text/index) is changed:
index in combobox_10 must set to equivalent number as in in 9@Karoluss96 said in If current text/index is change in combobox:
so close, but if-statements must be (in my point of view), because user can change the value/index EITHER in combobox_9 OR in combobox_10.
From this reply of yours, it seems you do not understand how Qt's signals and slots (and therefore the connect statements in @jsulm 's reply) work. If you do not understand them, I suggest you read (and re-read) the documentation on them. The code on that page is C++ but the concept is the same in Python too.
-
@mchinand said in If current text/index is change in combobox:
From this reply of yours, it seems you do not understand how Qt's signals and slots (and therefore the connect statements in @jsulm 's reply) work. If you do not understand them, I suggest you read (and re-read) the documentation on them. The code on that page is C++ but the concept is the same in Python too.
OK, I didn't know about this page. If still have problems after next unsolving problems. I'll write