Add title to pyqt list

I want to add headers and index to the list in pyqt, it really doesn't matter which QT list (qlistwidget, qlistview, qtablewidget, qtreeview)

In short, I want something like an example of delegating a box box in a pyqt demo ... but instead of an index in the column headers, I want rows ...



hope the idea is clear enough
thanx in advance

+4
source share
1 answer

QTableWidget is most likely your best bet - it uses setHorizontalHeaderLabels() and setVerticalHeaderLabels() so you can 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 to completely control the content and formatting of the headers, you can use the .setHorizontalHeaderItem () and .setVerticalHeaderItem () methods to determine the QTableWidgetItem for each header ...

For more information, see the official documentation.

+6
source

Source: https://habr.com/ru/post/1308529/


All Articles