【问题标题】:Get QModelIndex from filepath and filename in QFileSystemModel从 QFileSystemModel 中的文件路径和文件名获取 QModelIndex
【发布时间】:2018-05-10 03:34:29
【问题描述】:

我需要从QFileSystemModel 中的文件路径和文件名中获取 QModelIndex。我看到有 index 函数接受 filepath 但我不知道列参数应该做什么。

【问题讨论】:

    标签: c++ qt qml qt5 qfilesystemmodel


    【解决方案1】:

    您必须覆盖 QFileSystemModel 的 index() 方法,以便可以从 QML 访问它:

    class DisplayFileSystemModel : public QFileSystemModel {
        Q_OBJECT
    public:
        ...
        Q_INVOKABLE QModelIndex index(const QString &path, int column = 0) const
        {
            return QFileSystemModel::index(path, column);    
        }
        ...
    };
    

    然后在 QML 中,您可以使用以下形式:

    your_model.index(your_fullpath)
    

    【讨论】:

      猜你喜欢
      • 2023-03-26
      • 2013-12-08
      • 2012-01-21
      • 2012-10-25
      • 1970-01-01
      • 2011-11-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多