Rao*_*Rao 5 python header qtableview pyqt4
我想知道如何在QTableview中设置自定义标题名称
当我创建一个QTableview时,我得到列和行标题名称为1,2,3,4.我想知道如何设置自己的列和标题标题.
我根据需要得到了解决方案,希望它可以帮助遇到相同情况的人
Gar*_*hes 11
如果您使用QTableView自己的模型,则需要headerData()在模型中实现该方法以返回标题的数据.这是一个仅显示列标题的代码段 - 更改header_labels值以更改标题文本.
class TableModel(QAbstractTableModel):
header_labels = ['Column 1', 'Column 2', 'Column 3', 'Column 4']
def __init__(self, parent=None):
QAbstractTableModel.__init__(self, parent)
def headerData(self, section, orientation, role=Qt.DisplayRole):
if role == Qt.DisplayRole and orientation == Qt.Horizontal:
return self.header_labels[section]
return QAbstractTableModel.headerData(self, section, orientation, role)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11048 次 |
| 最近记录: |