Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 从QPersistentModelIndex获取QModelIndex_Python_Pyqt_Pyqt5 - Fatal编程技术网

Python 从QPersistentModelIndex获取QModelIndex

Python 从QPersistentModelIndex获取QModelIndex,python,pyqt,pyqt5,Python,Pyqt,Pyqt5,我有一个QSortFilterProxyModel,我需要选择要删除的行,所以我使用的是QPersistentModelIndexQPersistentModelIndex可以很好地处理多行选择,而其他方法不能删除所有行。我的问题是,我无法使用QPersistentModelIndex映射到Source,它需要QModelIndex。我怎样才能克服这个问题 model = QStandardItemModel() filter = QSortFilterProxyModel()

我有一个
QSortFilterProxyModel
,我需要选择要删除的行,所以我使用的是
QPersistentModelIndex
QPersistentModelIndex
可以很好地处理多行选择,而其他方法不能删除所有行。我的问题是,我无法使用
QPersistentModelIndex
映射到Source,它需要
QModelIndex
。我怎样才能克服这个问题

    model = QStandardItemModel()
    filter = QSortFilterProxyModel()
    self.filter.setSourceModel(model)
    # Set the model/check function
    table_view = QTableView()        
    table_view.setModel(filter)

    # Delete Row using 
    index_list = []                                                          
    for model_index in table_view.selectionModel().selectedRows():       
        index = QPersistentModelIndex(model_index)         
        index_list.append(index)                                         

    if index_list:
       for index in index_list: 
           "The error is here, it only accepts `QModelIndex` and refuses `QPersistentModelIndex`"
           ix      = table_view.model().mapToSource(index.row())  
           # ix      = table_view.model().mapToSource(index)            
           item    = model.itemFromIndex(ix)

如果要将QPersistentModelIndex转换为QModelIndex,只需使用:

for p_index in index_list: 
    index = QModelIndex(p_index)
    ix = table_view.model().mapToSource(index)