QFileSystemModel不适用于QSortFilterProxyModel

问题描述 投票:0回答:1

我有QfileSysteModel和QSortFilterProxyModel。当我尝试调用QfileSysteModel.filePath以获取文件的当前索引时,错误发生为core Dump。这是一段代码

    le = QLineEdit()
    lv = QListView()

    file_model = QFileSystemModel()
    file_model.setRootPath(QtCore.QDir.rootPath())

    proxy_model = QSortFilterProxyModel(
        recursiveFilteringEnabled=True,
        filterRole=QtWidgets.QFileSystemModel.FileNameRole)
    proxy_model.setSourceModel(file_model)
    lv.setModel(self.proxy_model)

它很好,但是当我尝试调用QFileSystemModel Core Dumps的任何方法时。例如

filepath  = file_model.filePath(lv.currentIndex())

如何使用QfileSystemModel的任何方法

python pyqt pyqt5 qfilesystemmodel
1个回答
0
投票

[使用代理模型时,代理的ModelIndex与源模型中的索引不同。使用mapToSource()从代理模型转换为源模型。

在您的情况下,可能看起来像这样:

mapToSource()
© www.soinside.com 2019 - 2024. All rights reserved.