diff options
| author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2024-09-18 07:36:20 +0200 |
|---|---|---|
| committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2024-09-18 08:28:04 +0200 |
| commit | e4199ec3881d8e556385af98084856be857e0dbe (patch) | |
| tree | 77b264f5a21cff9f131a6b27e3b5142745faf91f /examples/widgets/tutorials/modelview | |
| parent | f48433db9a5be32c0b401c1d5203853abbff6c32 (diff) | |
type hints: Fix some typing bugs for mypy (forgiveness)
The new enums still support old syntax by the forgiveness mode.
Nevertheless, when using mypy to check files, strict correctness
is enforced.
We correct a large number of forgiveness-induced errors,
but there is still a whole lot of other complaints to fix.
Task-number: PYSIDE-2846
Change-Id: If566187d268ef75bc09b8d86f73d2c7d19f284f9
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'examples/widgets/tutorials/modelview')
6 files changed, 18 insertions, 18 deletions
diff --git a/examples/widgets/tutorials/modelview/1_readonly.py b/examples/widgets/tutorials/modelview/1_readonly.py index 4606bc47b..92402eb26 100644 --- a/examples/widgets/tutorials/modelview/1_readonly.py +++ b/examples/widgets/tutorials/modelview/1_readonly.py @@ -21,8 +21,8 @@ class MyModel(QAbstractTableModel): def columnCount(self, parent=None): return 3 - def data(self, index, role=Qt.DisplayRole): - if role == Qt.DisplayRole: + def data(self, index, role=Qt.ItemDataRole.DisplayRole): + if role == Qt.ItemDataRole.DisplayRole: row = index.row() + 1 column = index.column() + 1 return f"Row{row}, Column{column}" diff --git a/examples/widgets/tutorials/modelview/2_formatting.py b/examples/widgets/tutorials/modelview/2_formatting.py index 70cbda03b..07833bbd5 100644 --- a/examples/widgets/tutorials/modelview/2_formatting.py +++ b/examples/widgets/tutorials/modelview/2_formatting.py @@ -22,34 +22,34 @@ class MyModel(QAbstractTableModel): return 3 #! [1] - def data(self, index, role=Qt.DisplayRole): + def data(self, index, role=Qt.ItemDataRole.DisplayRole): row = index.row() col = index.column() # generate a log message when this method gets called print(f"row {row}, col{col}, role {role}") - if role == Qt.DisplayRole: + if role == Qt.ItemDataRole.DisplayRole: if row == 0 and col == 1: return "<--left" if row == 1 and col == 1: return "right-->" return f"Row{row}, Column{col + 1}" - elif role == Qt.FontRole: + elif role == Qt.ItemDataRole.FontRole: if row == 0 and col == 0: # change font only for cell(0,0) bold_font = QFont() bold_font.setBold(True) return bold_font - elif role == Qt.BackgroundRole: + elif role == Qt.ItemDataRole.BackgroundRole: if row == 1 and col == 2: # change background only for cell(1,2) return QBrush(Qt.red) - elif role == Qt.TextAlignmentRole: + elif role == Qt.ItemDataRole.TextAlignmentRole: if row == 1 and col == 1: # change text alignment only for cell(1,1) return Qt.AlignRight | Qt.AlignVCenter - elif role == Qt.CheckStateRole: + elif role == Qt.ItemDataRole.CheckStateRole: if row == 1 and col == 0: # add a checkbox to cell(1,0) return Qt.Checked diff --git a/examples/widgets/tutorials/modelview/3_changingmodel.py b/examples/widgets/tutorials/modelview/3_changingmodel.py index bc6661e66..251940221 100644 --- a/examples/widgets/tutorials/modelview/3_changingmodel.py +++ b/examples/widgets/tutorials/modelview/3_changingmodel.py @@ -27,10 +27,10 @@ class MyModel(QAbstractTableModel): return 3 #! [2] - def data(self, index, role=Qt.DisplayRole): + def data(self, index, role=Qt.ItemDataRole.DisplayRole): row = index.row() col = index.column() - if role == Qt.DisplayRole and row == 0 and col == 0: + if role == Qt.ItemDataRole.DisplayRole and row == 0 and col == 0: return QTime.currentTime().toString() return None #! [2] @@ -41,7 +41,7 @@ class MyModel(QAbstractTableModel): # we identify the top left cell top_left = self.createIndex(0, 0) # emit a signal to make the view reread identified data - self.dataChanged.emit(top_left, top_left, [Qt.DisplayRole]) + self.dataChanged.emit(top_left, top_left, [Qt.ItemDataRole.DisplayRole]) #! [3] diff --git a/examples/widgets/tutorials/modelview/4_headers.py b/examples/widgets/tutorials/modelview/4_headers.py index 91fbe16a7..12815abf3 100644 --- a/examples/widgets/tutorials/modelview/4_headers.py +++ b/examples/widgets/tutorials/modelview/4_headers.py @@ -20,8 +20,8 @@ class MyModel(QAbstractTableModel): def columnCount(self, parent=None): return 3 - def data(self, index, role=Qt.DisplayRole): - if role == Qt.DisplayRole: + def data(self, index, role=Qt.ItemDataRole.DisplayRole): + if role == Qt.ItemDataRole.DisplayRole: row = index.row() + 1 column = index.column() + 1 return f"Row{row}, Column{column}" @@ -29,7 +29,7 @@ class MyModel(QAbstractTableModel): #! [1] def headerData(self, section, orientation, role): - if role == Qt.DisplayRole and orientation == Qt.Horizontal: + if role == Qt.ItemDataRole.DisplayRole and orientation == Qt.Orientation.Horizontal: return ["first", "second", "third"][section] return None #! [1] diff --git a/examples/widgets/tutorials/modelview/5_edit.py b/examples/widgets/tutorials/modelview/5_edit.py index 450ac5072..ae57634b1 100644 --- a/examples/widgets/tutorials/modelview/5_edit.py +++ b/examples/widgets/tutorials/modelview/5_edit.py @@ -29,14 +29,14 @@ class MyModel(QAbstractTableModel): def columnCount(self, parent=None): return COLS - def data(self, index, role=Qt.DisplayRole): - if role == Qt.DisplayRole and self.checkIndex(index): + def data(self, index, role=Qt.ItemDataRole.DisplayRole): + if role == Qt.ItemDataRole.DisplayRole and self.checkIndex(index): return self._grid_data[index.row()][index.column()] return None #! [1] def setData(self, index, value, role): - if role != Qt.EditRole or not self.checkIndex(index): + if role != Qt.ItemDataRole.EditRole or not self.checkIndex(index): return False # save value from editor to member m_gridData self._grid_data[index.row()][index.column()] = value diff --git a/examples/widgets/tutorials/modelview/7_selections.py b/examples/widgets/tutorials/modelview/7_selections.py index 0a4638bcf..180fd9b11 100644 --- a/examples/widgets/tutorials/modelview/7_selections.py +++ b/examples/widgets/tutorials/modelview/7_selections.py @@ -54,7 +54,7 @@ class MainWindow(QMainWindow): def selection_changed_slot(self, new_selection, old_selection): # get the text of the selected item index = self._tree_view.selectionModel().currentIndex() - selected_text = index.data(Qt.DisplayRole) + selected_text = index.data(Qt.ItemDataRole.DisplayRole) # find out the hierarchy level of the selected item hierarchy_level = 1 seek_root = index |
