Populate QComboBox with a list

0 votes

I'm developing a GUI dialog using PyQT4 which imports some data into a Pandas DataFrame and then plots the data to an embedded Matplotlib canvas.

I'd like to pass a list of variable from the DataFrame to the combo box. My first attempt was:

list = list(df.parameter,unique())
self.FirstComboBox = QtGui.QComboBox()
self.FirstComboBox.addItems(list)

But on running this I get

TypeError: QComboBox.addItems(QStringList): argument 1 has unexpected type 'list'

I've seen examples where a sorted list of dict keys is passed to a combo box, so I'm confused that I can't pass a list.

Jul 3, 2019 in Python by ana1504.k
• 7,900 points
529 views

1 answer to this question.

0 votes

It looks like you're using the old v1 api. You can use the newer api, which removes the need for casting strings to QStrings (or QStringLists in this case).

import sip
# Do this before you import PyQt
sip.setapi('QString', 2)

from PyQt4 import QtCore
answered Jul 3, 2019 by SDeb
• 13,270 points

Related Questions In Python

0 votes
1 answer

How to zip with a list output in Python instead of a tuple output?

Good question - Considering that you are ...READ MORE

answered Feb 7, 2019 in Python by Nymeria
• 3,520 points
516 views
0 votes
1 answer

How to produce a list with unique elements from a list with duplicate elements?

Hey, @Roshni, Iterating the list is not a ...READ MORE

answered Jun 26, 2020 in Python by Gitika
• 65,870 points
791 views
+2 votes
4 answers

How can I replace values with 'none' in a dataframe using pandas

Actually in later versions of pandas this ...READ MORE

answered Aug 13, 2018 in Python by bug_seeker
• 15,550 points
39,302 views
+2 votes
2 answers

In a list of dictionaries, how can I find the minimum calue in a common dictionary field.

There are several options. Here is a ...READ MORE

answered Apr 10, 2018 in Python by charlie_brown
• 7,780 points
428 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 2,045 views
0 votes
0 answers
0 votes
1 answer

Return a list inside a for loop while iterating over the elements of another list

The print() is getting called multiple times ...READ MORE

answered Sep 21, 2018 in Python by SDeb
• 13,270 points
692 views
0 votes
1 answer

How to Reverse a list in Python

You can use the reversed function in ...READ MORE

answered Sep 28, 2018 in Python by SDeb
• 13,270 points
251 views