我正在尝试使用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
}
}