Tableview 使用 QSqlRelationalTableModel。如何从垂直标题的列中插入数据?
问问题
1344 次
1 回答
0
最简单的方法是继承QSqlRelationalTableModel
和覆盖headerData
方法(负责显示标题的数据:
class MyModel(QtSql.QSqlRelationalTableModel):
def headerData(self, section, orientation, role=QtCore.Qt.DisplayRole):
if orientation == QtCore.Qt.Vertical:
index = self.index(section, 0) # assuming ID is the first column
return self.data(index, role)
else:
# return original headers for horizontal orientation
return super(MyModel, self).headerData(section, orientation, role)
然后用这个代替QSqlRelationalTableModel
. 如果需要,您可以在with中隐藏该ID
列(因为它会被复制):QTableView
setColumnHidden
myTableView.setColumnHidden(0, True) # again assuming ID is the first column
于 2012-11-19T21:53:47.550 回答