checking and adding into combobox
-
Hi everyone,
I need to add into combobox a year (from line_edit).
I inspired by the link below:
https://stackoverflow.com/questions/7479915/getting-all-items-of-qcombobox-pyqt4-python
but the difference in my problem is that: I need add ONLY IF put in line_edit doesn't exist. eg.Now the combox have records: [2017, 2018,2020,2021,2022,2023,2025,2030]
So if I put in line_edit: 2024 It put to combobox because isn't in it/
But accoring to code form link above, f I put in line_edit: 2023 it also add to combobox, wheras isn't need as this year appear in combobox.I've try sth like that:
year = self.dlg.lineEdit_13.text() Allyear = [self.dlg.comboBox_14.itemText(i) for i in range(self.dlg.comboBox_14.count())] #from attached link if year != Allyear: self.dlg.comboBox_14.addItem(year)Thanks for every help!
-
Hi everyone,
I need to add into combobox a year (from line_edit).
I inspired by the link below:
https://stackoverflow.com/questions/7479915/getting-all-items-of-qcombobox-pyqt4-python
but the difference in my problem is that: I need add ONLY IF put in line_edit doesn't exist. eg.Now the combox have records: [2017, 2018,2020,2021,2022,2023,2025,2030]
So if I put in line_edit: 2024 It put to combobox because isn't in it/
But accoring to code form link above, f I put in line_edit: 2023 it also add to combobox, wheras isn't need as this year appear in combobox.I've try sth like that:
year = self.dlg.lineEdit_13.text() Allyear = [self.dlg.comboBox_14.itemText(i) for i in range(self.dlg.comboBox_14.count())] #from attached link if year != Allyear: self.dlg.comboBox_14.addItem(year)Thanks for every help!
@Karoluss96 Did you do any debugging?
What is the value of Allyear and what is the value of year? -
@Karoluss96 Did you do any debugging?
What is the value of Allyear and what is the value of year?@jsulm debug without bug.
Allyear are all records from combobox: ['2017', '2018', '2019', '2020', '2021', '2022', '2023', '2025', '2030']
year is 2023
-
Hi everyone,
I need to add into combobox a year (from line_edit).
I inspired by the link below:
https://stackoverflow.com/questions/7479915/getting-all-items-of-qcombobox-pyqt4-python
but the difference in my problem is that: I need add ONLY IF put in line_edit doesn't exist. eg.Now the combox have records: [2017, 2018,2020,2021,2022,2023,2025,2030]
So if I put in line_edit: 2024 It put to combobox because isn't in it/
But accoring to code form link above, f I put in line_edit: 2023 it also add to combobox, wheras isn't need as this year appear in combobox.I've try sth like that:
year = self.dlg.lineEdit_13.text() Allyear = [self.dlg.comboBox_14.itemText(i) for i in range(self.dlg.comboBox_14.count())] #from attached link if year != Allyear: self.dlg.comboBox_14.addItem(year)Thanks for every help!
@Karoluss96 said in checking and adding into combobox:
if year != Allyear:
Shouldn't this be:
if not year in Allyear:?
-
@jsulm debug without bug.
Allyear are all records from combobox: ['2017', '2018', '2019', '2020', '2021', '2022', '2023', '2025', '2030']
year is 2023
@Karoluss96
Allyearis a list/array.yearis a single value.year != Allyearwill always be true. -
@Karoluss96 said in checking and adding into combobox:
if year != Allyear:
Shouldn't this be:
if not year in Allyear:?
@jsulm Yes it works. Thanks!
Friday afternoon is not good for thinking