2
0
mirror of https://github.com/pyqt/examples.git synced 2025-08-22 09:37:11 +00:00

Fix 14 QAbstractTableModel example

This commit is contained in:
dongliu 2022-05-18 15:38:21 +08:00
parent 6ba2eb7860
commit f23cbb2196
2 changed files with 4 additions and 4 deletions

View File

@ -31,12 +31,12 @@ class TableModel(QAbstractTableModel):
# How many columns?
return len(headers)
def data(self, index, role):
if role != Qt.DisplayRole:
if role != Qt.ItemDataRole.DisplayRole:
return QVariant()
# What's the value of the cell at the given index?
return rows[index.row()][index.column()]
def headerData(self, section, orientation, role):
if role != Qt.DisplayRole or orientation != Qt.Horizontal:
if role != Qt.ItemDataRole.DisplayRole or orientation != Qt.Orientation.Horizontal:
return QVariant()
# What's the header for the given column?
return headers[section]

View File

@ -12,11 +12,11 @@ class TableModel(QAbstractTableModel):
def columnCount(self, parent):
return len(headers)
def data(self, index, role):
if role != Qt.DisplayRole:
if role != Qt.ItemDataRole.DisplayRole:
return QVariant()
return rows[index.row()][index.column()]
def headerData(self, section, orientation, role):
if role != Qt.DisplayRole or orientation != Qt.Horizontal:
if role != Qt.ItemDataRole.DisplayRole or orientation != Qt.Orientation.Horizontal:
return QVariant()
return headers[section]