View Full Version : Changing the title of a column in the QDirModel object
janca
11th April 2007, 13:34
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:
guilugi
11th April 2007, 13:42
You'll have to subclass QDirModel and reimplement the headerData() method.
Something like this :
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:
return QVariant();
}
}
return QVariant();
}
This example applies to a QTreeView with a single column :)
janca
12th April 2007, 11:11
Wow! That's an amazing solution. Thank you. :rolleyes:
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.