Search code examples
pythonpython-3.xpyqtpyqt5qcombobox

Adding two variables to a QComboBox


Here's my code snippet:

self.cursor.execute("MATCH (n:Person) RETURN n.firstname, n.lastname")
for i in self.cursor:
    self.cbPerson.addItem(str(i[0])

This gives me a list of the firstnames.

self.cbPerson.addItem(str(i[0:3])

This gives me the first and last name but like this ('firstname','lastname')

how do I get the desired output: firstname lastname


Solution

  • Use join:

    for i in self.cursor:
        self.cbPerson.addItem(" ".join(i))
    

    or better:

    self.cbPerson.addItems([" ".join(i) for i in self.cursor])