Unfortunately there's no (Qt-native) way to label a QListView
(on which QListWidget
is based). If your really don't want additional widgets, I would instead use a single-column QTableWidget
, and put the list title in the column header. QTableWidget
and QListWidget
work pretty similarly, so this probably won't break too much of your existing code.
An example based on yours:
class MyApp(object):
def __init__(self):
# snipped
self.listA = self.prepareTableWidget('List A')
self.listB = self.prepareTableWidget('List B')
# snipped
def prepareTableWidget(self, name):
table = QtGui.QTableWidget()
table.setColumnCount(1)
table.setHorizontalHeaderLabels([name])
table.horizontalHeader().setResizeMode(QtGui.QHeaderView.Stretch)
return table
# snipped