非常簡單的任務,但我沒有設法找到任何有用的文檔。我希望QTreeView包含一個名爲「Files」的列,其中包含來自QFileSystemView的數據。這裏是我得到的:QTreeView/QFileSystemModel設置標題標籤
QFileSystemModel *projectFiles = new QFileSystemModel();
projectFiles->setRootPath(QDir::currentPath());
ui->filesTree->setModel(projectFiles);
ui->filesTree->setRootIndex(projectFiles->index(QDir::currentPath()));
// hide all but first column
for (int i = 3; i > 0; --i)
{
ui->filesTree->hideColumn(i);
}
這給了我一個帶有「名稱」標題的列。我如何重命名這個頭文件?
我只是想相同的(使用'setHeaderData()'),但它沒有工作。查看源代碼'src/gui/dialogs/qfilesystemmodel.cpp' - 頭文件被硬編碼在那裏:(所以,對'QFileSystemModel'進行子類化並重載'headerData()'是正確的解決方案。 –