diff options
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 |
