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()

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 in Python by ana1504.k
• 7,870 points

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 by SDeb
• 13,160 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 in Python by Nymeria
• 3,520 points
+2 votes
2 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,350 points
+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,720 points
+4 votes
7 answers

Splitting a List into chunks in Python

Here's a generator that yields the chunks ...READ MORE

answered Apr 13, 2018 in Python by Nietzsche's daemon
• 4,260 points
+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 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 216 views
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,160 points
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,160 points