Hi guys. I met a problem when I wanted to rename my column headers. I used Table view.

My re-implemented 'headerData' and 'setHeaderData' in tablemodel.cpp look like below:

Qt Code:
  1. QVariant TableModel::headerData(int section, Qt::Orientation orientation, int role) const
  2. {
  3. if (role != Qt::DisplayRole)
  4. return QVariant();
  5.  
  6. if (orientation == Qt::Horizontal){
  7. //qDebug()<<headerdata.at(section);
  8. return headerdata.at(section);
  9. }
  10. return QVariant();
  11. }
  12.  
  13. bool TableModel::setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role)
  14. {
  15. if (section < headerdata.size() && role == Qt::EditRole)
  16. {
  17. headerdata.replace(section, value.toString());
  18. //qDebug()<<section;
  19. emit headerDataChanged(orientation,section,section);
  20. return true;
  21. }
  22. return false;
  23. }
To copy to clipboard, switch view to plain text mode 

Is there anything wrong? Or if it's not wrong, why I can't edit columns header?
What I want is that the headers can be editable like other data, i.e. click one column header then type then press return then it will update.

Please help me. Thanks in advance!