editor = table.currentEditor() 不存在
时间: 2024-02-11 12:05:55 浏览: 32
对不起,我的回答还有误。在 PyQT5 中,`QTableView` 并没有提供 `currentEditor()` 方法。可以通过 `QAbstractItemView` 的 `currentIndex()` 方法获取当前选中的单元格的索引,然后通过 `QAbstractItemView` 的 `indexWidget()` 方法获取该单元格的 editor。以下是正确的代码示例:
```python
index = table.currentIndex() # 获取当前选中的单元格的索引
editor = table.indexWidget(index) # 获取该单元格的 editor
if editor is not None:
table.closeEditor(editor, QtWidgets.QAbstractItemDelegate.NoHint)
```
其中,`table` 是 `QTableView` 的实例,`currentIndex()` 方法会返回当前选中的单元格的索引,如果没有选中任何单元格,则返回 `QModelIndex()`。`indexWidget()` 方法的参数是要获取的单元格的索引,返回该单元格的 editor,如果该单元格没有 editor,则返回 `None`。
需要注意的是,如果当前没有单元格处于编辑状态,该方法不会有任何效果。
相关推荐
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)