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,910 points
1,770 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,300 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,560 points
1,772 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,770 points
3,594 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,510 points
122,346 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,720 points
1,420 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 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,443 views
0 votes
1 answer
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 22, 2018 in Python by SDeb
• 13,300 points
5,040 views
0 votes
1 answer

How to Reverse a list in Python

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

answered Sep 29, 2018 in Python by SDeb
• 13,300 points
848 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP