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. QCompleter change value in all ComboBoxs
Forum Updated to NodeBB v4.3 + New Features

QCompleter change value in all ComboBoxs

Scheduled Pinned Locked Moved Unsolved Qt for Python
7 Posts 3 Posters 977 Views 2 Watching
  • 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.
  • F Offline
    F Offline
    Falassion
    wrote on last edited by Falassion
    #1

    Hi,

    i'm trying to set Qcompleter and seems work fine except for this problem. I have a lot of ComboBox and when i edit one of them using Qcompleter fuction the program change all value in the other comboboxs. Why?

    import sys
    from PyQt5 import QtCore, QtGui, QtWidgets as qtw
    from PyQt5 import QtGui as qtg
    from PyQt5 import QtCore as qtc
    from PyQt5.QtWidgets import QCompleter, QTableWidget, QTableWidgetItem
    from PyQt5.QtGui import QFont, QStandardItem, QStandardItemModel, QFont
    import csv
    
    class MainWindow(qtw.QWidget):
    
       def __init__(self):
           super().__init__()
    
           groupbox_colazione = qtw.QGroupBox('COLAZIONE')
           groupbox_colazione.setMaximumWidth(400)
           groupbox_colazione_layout = qtw.QGridLayout()    
    
           with open ('prova_lavorazione.csv') as file:
               
               lista_alimenti = csv.reader(file, delimiter=';')
    
               completamento = []
    
               for row in lista_alimenti:
           
                   completamento.append(row[1])
    
               
           completer = qtw.QCompleter(completamento)
    
           self.elenco_alimenti_colazione = []
           self.grammi_colazione = []
    
           for i in range (18):
    
              elenco_alimenti = qtw.QComboBox()
              elenco_alimenti.setMaximumWidth(200) 
              elenco_alimenti.setEditable(True)
    
              self.elenco_alimenti_colazione.append(elenco_alimenti) 
    
              grammi_colazione = qtw.QLineEdit(placeholderText='Grammi..')   
              grammi_colazione.setMaximumWidth(50)  
    
              self.grammi_colazione.append(grammi_colazione)   
    
           with open ('prova_lavorazione.csv') as file:
               
               lista_alimenti = csv.reader(file, delimiter=';')
    
               completamento = []
    
               for i in range (18):
    
                   self.elenco_alimenti_colazione[i].addItem('')
    
               for row in lista_alimenti:
    
                   for i in range (18):
    
                       self.elenco_alimenti_colazione[i].addItem(row[1])
                       self.elenco_alimenti_colazione[i].setCompleter(completer)
    
           groupbox_colazione = qtw.QGroupBox('COLAZIONE')
           groupbox_colazione.setMaximumWidth(900)
           groupbox_colazione_layout = qtw.QGridLayout()
           groupbox_colazione.setLayout(groupbox_colazione_layout)
    
           for i in range(6):
    
               groupbox_colazione_layout.addWidget(self.elenco_alimenti_colazione[i], i, 0)
    
           for i in range(6):
               
               groupbox_colazione_layout.addWidget(self.grammi_colazione[i], i, 1)
    
           y = 0
    
           for i in range(6,12):
    
               groupbox_colazione_layout.addWidget(self.elenco_alimenti_colazione[i], y, 2)
               y += 1
    
           y = 0
    
           for i in range(6,12):
               
               groupbox_colazione_layout.addWidget(self.grammi_colazione[i], y, 3)
               y += 1
    
           y = 0
    
           for i in range(12,18):
    
               groupbox_colazione_layout.addWidget(self.elenco_alimenti_colazione[i], y, 4)
               y += 1
    
           y = 0
    
           for i in range(12,18):
               
               groupbox_colazione_layout.addWidget(self.grammi_colazione[i], y, 5)
               y += 1
    
       
           main_layout = qtw.QGridLayout()
           main_layout.addWidget(groupbox_colazione, 0, 0) 
    
           self.setLayout(main_layout)   
    
           self.show()
    
    if __name__ == '__main__':
    
       app = qtw.QApplication(sys.argv)
       mw = MainWindow()
       sys.exit(app.exec())
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Please use the coding tags for your code, it's almost unreadable.

      Also, please make it a minimal runnable script so it can be more easily tested.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • F Offline
        F Offline
        Falassion
        wrote on last edited by
        #3

        Thanks, done ! :p

        mrjjM 1 Reply Last reply
        0
        • F Falassion

          Thanks, done ! :p

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Falassion
          Hi
          it seem you are sharing the completer amount the combo boxes ?

          1 Reply Last reply
          1
          • F Offline
            F Offline
            Falassion
            wrote on last edited by
            #5

            @mrjj said in QCompleter change value in all ComboBoxs:

            @Falassion
            Hi
            it seem you are sharing the completer amount the combo boxes ?

            Do you mean i have to use different completer? How i can do?

            I need comboboxes with the same items list and a completer for each one.

            mrjjM 1 Reply Last reply
            0
            • F Falassion

              @mrjj said in QCompleter change value in all ComboBoxs:

              @Falassion
              Hi
              it seem you are sharing the completer amount the combo boxes ?

              Do you mean i have to use different completer? How i can do?

              I need comboboxes with the same items list and a completer for each one.

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Falassion

              You just need to do
              completer = qtw.QCompleter(completamento)
              for each

              self.elenco_alimenti_colazione[i].setCompleter(completer)

              They can use same list (completamento)

              Im 100% python noob but might be like

               for i in range (18):
                    self.elenco_alimenti_colazione[i].addItem(row[1])
                    self.elenco_alimenti_colazione[i].setCompleter( qtw.QCompleter(completamento) )
              
              

              so each gets its own instance (but same list )

              F 1 Reply Last reply
              1
              • mrjjM mrjj

                @Falassion

                You just need to do
                completer = qtw.QCompleter(completamento)
                for each

                self.elenco_alimenti_colazione[i].setCompleter(completer)

                They can use same list (completamento)

                Im 100% python noob but might be like

                 for i in range (18):
                      self.elenco_alimenti_colazione[i].addItem(row[1])
                      self.elenco_alimenti_colazione[i].setCompleter( qtw.QCompleter(completamento) )
                
                

                so each gets its own instance (but same list )

                F Offline
                F Offline
                Falassion
                wrote on last edited by
                #7

                @mrjj said in QCompleter change value in all ComboBoxs:

                @Falassion

                You just need to do
                completer = qtw.QCompleter(completamento)
                for each

                self.elenco_alimenti_colazione[i].setCompleter(completer)

                They can use same list (completamento)

                Im 100% python noob but might be like

                 for i in range (18):
                      self.elenco_alimenti_colazione[i].addItem(row[1])
                      self.elenco_alimenti_colazione[i].setCompleter( qtw.QCompleter(completamento) )
                
                

                so each gets its own instance (but same list )

                Thanks ! It work! :D

                1 Reply Last reply
                1

                • Login

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