我希望能在PyQt中为列表添加标题和索引,无论是QT的哪个列表(qlistwidget、qlistview、qtablewidget、qtreeview)都不重要。简而言之,我想要像PyQt演示中旋转框委托示例一样的东西...但是我希望列标题中的索引是字符串而不是数字。希望这个想法足够清晰明了。谢谢!
QTableWidget可能是您的最佳选择 - 它使用setHorizontalHeaderLabels()
和setVerticalHeaderLabels()
让您控制两个轴。
from PyQt4 import QtGui
class MyWindow(QtGui.QMainWindow):
def __init__(self, parent):
QtGui.QMainWindow.__init__(self, parent)
table = QtGui.QTableWidget(3, 3, self) # create 3x3 table
table.setHorizontalHeaderLabels(('Col 1', 'Col 2', 'Col 3'))
table.setVerticalHeaderLabels(('Row 1', 'Row 2', 'Row 3'))
for column in range(3):
for row in range(3):
table.setItem(row, column, QtGui.QWidget(self)) # your contents
self.setCentralWidget(table)
self.show()