[Qt-interest] header Data of Tree Model is Read-Only??

Gan Xiebin gan.xiebin at gmail.com
Tue May 26 11:54:58 CEST 2009


Hi All,

I want to set header data of my tree model ,
like so:

//  myTreeModel.cpp

myTreeModel::myTreeModel( QObject *parent )
     : QAbstractItemModel(parent)
 {
     QList<QVariant> rootData;
     rootData << "Name" << "IP" << "Status";
     rootNode = new Node(rootData);
 }

 QVariant myTreeModel::headerData(int section, Qt::Orientation orientation,
                                int role) const
 {
     if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
         return rootNode->data(section);

     return QVariant();
 }


 Qt::ItemFlags myTreeModel::flags(const QModelIndex &index) const
 {
     if (!index.isValid())
         return 0;

     return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable;
 }

 bool myTreeModel::setHeaderData(int section, Qt::Orientation orientation,
                               const QVariant &value, int role)
 {
     if (role != Qt::EditRole || orientation != Qt::Horizontal)
         return false;

     bool result = rootNode->setData(section, value);

     if (result)
         emit headerDataChanged(orientation, section, section);

     return result;
 }

------------------------------------


When I used QTreeView to display my Tree Model data,
I found that, normal data shows fine and is editable.
but the header data can not be edited ...

Did I missing something ??

Thanks,

Bin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090526/b079a26d/attachment.html 


More information about the Qt-interest-old mailing list