I want to retrieve a list of people's names from a queue and, for each person, place a checkbox with their name to a QGridLayout using the addWidget() function. I can successfully place the items in a QListView, but they just write over the top of each other rather than creating a new row. Does anyone have any thoughts on how I could fix this?
self.chk_People = QtGui.QListView()
items = self.jobQueue.getPeopleOffQueue()
for item in items:
QtGui.QCheckBox('%s' % item, self.chk_People)
self.jobQueue.getPeopleOffQueue() would return something like ['Bob', 'Sally', 'Jimmy'] if that helps.
This line:
QtGui.QCheckBox('%s' % item, self.chk_People)
Doesn't add the check box to the list view, it only creates it with the list view as the parent, and there's a big difference.
The simplest way to use a list view is the QListWidget
convenience class. For that, create your checkboxes as instances of QListWidgetItem
and then use addItem
on the list widget to really add them to it.
Did you have a problem adding them to a grid layout? Usually, if the amount of checkboxes you have is small a grid layout might be better - it all depends on how you want your app to look. But if you might have a lot of such objects, then a list widget/view is the best.