为什么会出现类型错误:PySide2.QtCore.QStringListModel.setData():参数不足

2024-09-30 12:28:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试像这样向PySide2中的QStringListModel添加新字符串

self.model = QStringListModel()
n = self.model.rowCount()
self.model.insertRow(n)
i = self.model.index(n,0)
self.model.setData(index= i,value='Hello World!!',role=Qt.EditRole)

它运行正常,直到insertRow(), 但是我有一个 TypeError:PySide2.QtCore.QStringListModel.setData():参数不足 在最后一行。 因为我填充了这个函数中的所有参数。 这个错误是如何产生的,如何解决? 请帮帮我


Tags: 字符串selfhelloworld参数indexmodelvalue
1条回答
网友
1楼 · 发布于 2024-09-30 12:28:41

QStringListModel::setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole)

Reimplements: QAbstractItemModel::setData(const QModelIndex &index, const QVariant &value, int role).

Sets the data for the specified role in the item with the given index in the model, to the provided value.

The dataChanged() signal is emitted if the item is changed. Returns true after emitting the dataChanged() signal.

改变

self.model.setData(index= i,value='Hello World!!',role=Qt.EditRole)

self.model.setData(i, 'Hello World!!', role=Qt.EditRole)

相关问题 更多 >

    热门问题