Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. checking and adding into combobox
Forum Updated to NodeBB v4.3 + New Features

checking and adding into combobox

Scheduled Pinned Locked Moved Solved Qt for Python
6 Posts 3 Posters 594 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Karoluss96K Offline
    Karoluss96K Offline
    Karoluss96
    wrote on last edited by
    #1

    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!

    jsulmJ 2 Replies Last reply
    0
    • Karoluss96K Karoluss96

      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!

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Karoluss96 Did you do any debugging?
      What is the value of Allyear and what is the value of year?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      Karoluss96K 1 Reply Last reply
      0
      • jsulmJ jsulm

        @Karoluss96 Did you do any debugging?
        What is the value of Allyear and what is the value of year?

        Karoluss96K Offline
        Karoluss96K Offline
        Karoluss96
        wrote on last edited by
        #3

        @jsulm debug without bug.

        Allyear are all records from combobox: ['2017', '2018', '2019', '2020', '2021', '2022', '2023', '2025', '2030']

        year is 2023

        JonBJ 1 Reply Last reply
        0
        • Karoluss96K Karoluss96

          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!

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Karoluss96 said in checking and adding into combobox:

          if year != Allyear:

          Shouldn't this be:

          if not year in Allyear:
          

          ?

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          Karoluss96K 1 Reply Last reply
          2
          • Karoluss96K Karoluss96

            @jsulm debug without bug.

            Allyear are all records from combobox: ['2017', '2018', '2019', '2020', '2021', '2022', '2023', '2025', '2030']

            year is 2023

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #5

            @Karoluss96
            Allyear is a list/array. year is a single value. year != Allyear will always be true.

            1 Reply Last reply
            3
            • jsulmJ jsulm

              @Karoluss96 said in checking and adding into combobox:

              if year != Allyear:

              Shouldn't this be:

              if not year in Allyear:
              

              ?

              Karoluss96K Offline
              Karoluss96K Offline
              Karoluss96
              wrote on last edited by
              #6

              @jsulm Yes it works. Thanks!
              Friday afternoon is not good for thinking

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved