pyqt5 setData
时间: 2023-11-15 22:06:49 浏览: 152
Set5-数据集
The `setData()` method in PyQt5 is used to set the data for a particular role in a model index. The method takes two arguments:
1. `role`: The role of the data that is being set. This can be any predefined role or a custom role defined by the user.
2. `value`: The value of the data that is being set.
Here is an example of how to use `setData()`:
```python
# create a model index
index = model.index(row, column)
# set the data for the DisplayRole
model.setData(index, "Hello World", QtCore.Qt.DisplayRole)
# set the data for a custom role
model.setData(index, "Custom Data", QtCore.Qt.UserRole+1)
```
In this example, we first create a model index using the `index()` method of the model. We then set the data for the `DisplayRole` using the value `"Hello World"`. Finally, we set the data for a custom role using the value `"Custom Data"`. Note that we specify the role using the `QtCore.Qt` namespace.
阅读全文