QML TreeView:显示工具提示

时间:2018-04-30 08:51:02

标签: qt qml

我正在尝试使用QML QFileSystemModel显示TreeView。我想将文件名显示为工具提示(因为空间有限,无法显示长文件名,因此我想将它们显示为工具提示)。我重写模型的数据函数(在我的类中派生自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中为了显示工具提示做些什么?

  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

        }
  }

0 个答案:

没有答案
相关问题