Changing the title of a column in the QDirModel object
I am using a QTreeView component to display the data of a QDirModel object. How can I change the title of the columns (Name, Size, Type, and Date Modified)? I have tried the following function but it has no desired effect:
// QDirModel m_dirmodel;
m_dirmodel->setHeaderData(0, Qt::Horizontal, "New name"); :confused:
Re: Changing the title of a column in the QDirModel object
You'll have to subclass QDirModel and reimplement the headerData() method.
Something like this :
Code:
QVariant CustomDirModel
::headerData(int section,
Qt::Orientation orientation,
int role) const
{
if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
{
switch (section)
{
case 0:
return tr("Arborescence");
default:
}
}
}
This example applies to a QTreeView with a single column :)
Re: Changing the title of a column in the QDirModel object
Wow! That's an amazing solution. Thank you. :rolleyes: