Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. If current text/index is change in combobox

If current text/index is change in combobox

Scheduled Pinned Locked Moved Unsolved General and Desktop
11 Posts 3 Posters 1.3k 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.
  • K Karoluss96
    22 Sept 2022, 11:25

    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

    J Offline
    J Offline
    jsulm
    Lifetime Qt Champion
    wrote on 22 Sept 2022, 11:37 last edited by
    #2

    @Karoluss96 Isn't it as simple as:

    self.dlg.comboBox_10.currentIndexChanged.connect(self.dlg.comboBox_2.setCurrentIndex)
    

    ?

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

    1 Reply Last reply
    0
    • K Offline
      K Offline
      Karoluss96
      wrote on 22 Sept 2022, 11:38 last edited by Karoluss96
      #3

      @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)
      
      J 1 Reply Last reply 22 Sept 2022, 11:41
      0
      • K Karoluss96
        22 Sept 2022, 11:38

        @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)
        
        J Offline
        J Offline
        jsulm
        Lifetime Qt Champion
        wrote on 22 Sept 2022, 11:41 last edited by
        #4

        @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)
        

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

        1 Reply Last reply
        0
        • K Offline
          K Offline
          Karoluss96
          wrote on 22 Sept 2022, 11:51 last edited by Karoluss96
          #5

          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

          J M 2 Replies Last reply 22 Sept 2022, 11:52
          0
          • K Karoluss96
            22 Sept 2022, 11:51

            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

            J Offline
            J Offline
            jsulm
            Lifetime Qt Champion
            wrote on 22 Sept 2022, 11:52 last edited by
            #6

            @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?

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

            1 Reply Last reply
            0
            • K Offline
              K Offline
              Karoluss96
              wrote on 22 Sept 2022, 12:07 last edited by Karoluss96
              #7

              @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?
              na forum.PNG

              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!

              J 1 Reply Last reply 22 Sept 2022, 12:38
              0
              • K Karoluss96
                22 Sept 2022, 12:07

                @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?
                na forum.PNG

                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!

                J Offline
                J Offline
                jsulm
                Lifetime Qt Champion
                wrote on 22 Sept 2022, 12:38 last edited by
                #8

                @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 ...
                

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

                1 Reply Last reply
                0
                • K Offline
                  K Offline
                  Karoluss96
                  wrote on 22 Sept 2022, 12:47 last edited by Karoluss96
                  #9

                  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)

                  1 Reply Last reply
                  0
                  • K Karoluss96
                    22 Sept 2022, 11:51

                    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

                    M Offline
                    M Offline
                    mchinand
                    wrote on 22 Sept 2022, 13:28 last edited by
                    #10

                    @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.

                    1 Reply Last reply
                    1
                    • K Offline
                      K Offline
                      Karoluss96
                      wrote on 22 Sept 2022, 13:31 last edited by
                      #11

                      @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

                      1 Reply Last reply
                      0

                      11/11

                      22 Sept 2022, 13:31

                      • Login

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