Python Forum
[PyQt] Help Iterating through to read comboBox Selections
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] Help Iterating through to read comboBox Selections
#1
Hello,

I have 22 ComboBoxes where the user can choose different values for each one.
The problem I'm having is that I don't know how to iterate through every single comboBox to see if there is a valid selection (a valid selection is anything but '-').
I tried if isinstance but it only reads the last comboBox and not the rest.

How do I make it, so it iterates through all 22 comboBoxes and stores the currentText() so I can use it to retrieve info (Main_Category, Sell_Price_$) from another Table within my SQLite Database.

Snippet:
#----------------------------------------------------------------------------------------------------
#                                      Button Actions
#----------------------------------------------------------------------------------------------------
        #------------------------------------------
                        #Submit Button
        #------------------------------------------
        #When the Submit button is clicked -> SubmitClicked Function
        SubmitButton = self.SubmitButton
        SubmitButton.clicked.connect(self.SubmitClicked)
        #------------------------------------------

#----------------------------------------------------------------------------------------------------
#                               Calculations
#----------------------------------------------------------------------------------------------------

        #------------------------------------------
        #  Subtract Material Used from Inventory
        #------------------------------------------
        #TODO:
        #Grab Main_Category where Name = Material_1-22_ComboBox.currentText()
        #If Main_Category is Wire: subtract MaterialQuantity from the Total_Length_Ft Column &
        #populate the MaterialPrice SpinBox with the Price_Per_Ft
        #Else, subtract the MaterialQuanity from the inventory Quantity &
        #populate the MaterialPrice SpinBox with the Sell_Price_$
        #Apply quantity changes once Submit Button is clicked

        #Make Database table in Inventory.db so it's easier to work with
        #------------------------------------------
    def SubmitClicked(self):

        for widget in self.MaterialUsedFrame.children():
            if isinstance(widget, QComboBox):
                SelectedItemName = widget.currentText()

        #Connect to the inventory database (inventory.db)
        connection = sqlite3.connect(InventoryDatabase)
        cursor = connection.cursor()
        cursor.execute("SELECT Main_Category FROM items WHERE Name = ?",(SelectedItemName,))
        connection.commit()
        Result = cursor.fetchone()
        #Close the connection
        connection.close()
        print(Result)

        if Result == ('Wire',):
            #Connect to the inventory database (inventory.db)
            connection = sqlite3.connect(InventoryDatabase)
            cursor = connection.cursor()
            cursor.execute("SELECT Total_Length_Ft, Price_Per_Ft FROM items WHERE Name = ?",(SelectedItemName,))
            connection.commit()
            Result = cursor.fetchone()
            #Close the connection
            connection.close()
            print(Result)

        else: 
            #Connect to the inventory database (inventory.db)
            connection = sqlite3.connect(InventoryDatabase)
            cursor = connection.cursor()
            cursor.execute("SELECT Quantity, Sell_Price_$ FROM items WHERE Name = ?",(SelectedItemName,))
            connection.commit()
            Result = cursor.fetchone()
            #Close the connection
            connection.close()
            print(Result)
#----------------------------------------------------------------------------------------------------
Thanks in advance.

Attached Files

Thumbnail(s)
   
Reply


Messages In This Thread
Help Iterating through to read comboBox Selections - by Extra - Aug-01-2022, 04:52 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyQt] How can I sync Combobox index to other combobox index? nickzsche 2 2,441 Jan-03-2022, 12:29 PM
Last Post: Axel_Erfurt
  [Tkinter] eport selections to dic mintsilver 0 2,401 Jan-16-2017, 01:06 PM
Last Post: mintsilver

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020