I am trying to add item in a QComboBox in PyQt5 using Python. I am having problems in adding data from the SQL Query per row.
cursor = cnx.cursor()
query = "SELECT buyerID, lastName, firstName, middleName FROM buyer ORDER BY id DESC LIMIT 5"
cursor.execute(query)
data = cursor.fetchall()
item = list()
for a, b, c, d in data:
row = "{} | {}, {} {}".format(a, b, c, d)
item.append(row)
self.customerID.addItem(str(item))
This results to only a single item added into the Combo Box:
100000 | lastName, firstName middleName, 100000 | lastName, firstName middleName, 100000 | lastName, firstName middleName...etc.
What I want to happen in the ComboBox is like this (Add a total of 5 items in the Combo Box)
100001 | lastName, firstName middleName
100002 | lastName, firstName middleName
100003 | lastName, firstName middleName
100004 | lastName, firstName middleName
100005 | lastName, firstName middleName
Edit:
cursor = cnx.cursor()
query = "SELECT buyerID, lastName, firstName, middleName FROM buyer ORDER BY id DESC LIMIT 5"
cursor.execute(query)
data = cursor.fetchall()
item = list()
for a, b, c, d in data:
row = "{} | {}, {} {}".format(a, b, c, d)
item.append(row)
self.customerID.addItem(str(item)) <------- I just moved this line of code into the FOR loop statement to add the item per loop.
Same Problem:
The appended Item added is still all the rows of data grouped into one.