i want to add a headers and index to a list in pyqt , it's really not important what list of QT (qlistwidget , qlistview , qtablewidget, qtreeview)
in short .. i want something like the spin box delegate example in the pyqt demo ...
but instead of the index in the column headers i want a strings ...
hope the idea is clear enough
thanx in advance
QTableWidget is likely your best choice - it uses setHorizontalHeaderLabels()
and setVerticalHeaderLabels()
to let you control both axes.
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()
Of course, if you want full control over the contents and formatting of the headers, then you could use the .setHorizontalHeaderItem() and .setVerticalHeaderItem() methods to define a QTableWidgetItem for each header...
See the official documentation for full details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With