Qt QML树视图:显示工具提示

Qt QML树视图:显示工具提示,qt,qml,Qt,Qml,我试图用QMLTreeView显示一个QFileSystemModel。我希望将文件名显示为工具提示(由于空间有限,无法显示长文件名,因此我希望将其显示为工具提示)。我重写了模型的数据函数(在我的类中是从QFileSystemModel派生的),如下所示 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE { if (index.isValid() &a

我试图用QML
TreeView
显示一个
QFileSystemModel
。我希望将文件名显示为工具提示(由于空间有限,无法显示长文件名,因此我希望将其显示为工具提示)。我重写了模型的数据函数(在我的类中是从
QFileSystemModel
派生的),如下所示

QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE
{
    if (index.isValid() && role == Qt::ToolTipRole) {
        return QVariant(fileInfo(index).fileName());
    }
我需要在我的
树视图中执行什么操作才能显示工具提示

  TreeView {
        id: view
        anchors.fill: parent
        sortIndicatorVisible: true
        model: fileSystemModel
        rootIndex: rootPathIndex
        selection: sel
        selectionMode: 2


        TableViewColumn {
            id: namecolumn
            title: "Name"
            role: "fileName"

            resizable: true
            width: parent.width-sizeWidth-dateWidth-scrollBarWidth
        }
        TableViewColumn {
            id: sizecolumn
            title: "Size"
            role: "size"
            resizable: false
            width: sizeWidth

        }
  }

创建自定义项委托并在该委托中使用工具提示QML类型。看,是的,那可能有用。那么TableView不支持开箱即用的工具提示?我问这个问题是因为小部件版本确实如此,对吗?没错。qml中使用的标准委托不支持工具提示。它的功能不如widgets版本。也许你应该把你的问题作为答案发布,因为它对我有用。