Hi,
i have created a pretty simple delegate to fix the size of the last column that get too big when i call setStretchLastSection(true) in the header (curious that if i don't call this method the column get the correct size and have a good margin until the end of the table), i have read the related post http://www.qtcentre.org/threads/1885...ustom-delegate but i can't find the problem in my code.

The delegate it is:
Qt Code:
  1. class LineasDelegate : public QStyledItemDelegate
  2. {
  3. Q_OBJECT
  4.  
  5. public:
  6. LineasDelegate(QObject *parent = 0) : QStyledItemDelegate(parent) {};
  7. QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
  8.  
  9. QSize LineasDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
  10. {
  11. std::cout << "sizeHint method delegate" << std::endl;
  12. }
To copy to clipboard, switch view to plain text mode 

I create it and attach to the TableView with this code:

Qt Code:
  1. ui->tableView->setAlternatingRowColors(true);
  2. ui->tableView->verticalHeader()->setDefaultSectionSize(ui->tableView->fontMetrics().lineSpacing() + 8);
  3.  
  4. lineasDelegate = new LineasDelegate();
  5. ui->tableView->setItemDelegate(lineasDelegate);
To copy to clipboard, switch view to plain text mode 

And after attach my custom model i call ui->tableView->resizeColumnsToContents(), still the method get not called ever, i have tried to add too at the data method of my custom model:

Qt Code:
  1. if (role == Qt::SizeHintRole) {
  2. std::cout << "data method sizeHintRole" << std::endl;
  3. }
To copy to clipboard, switch view to plain text mode 

That does not get called either. The only way i have found to set the size of the column it is using ui->tableView->horizontalHeader()->resizeSection(section, size) but i would prefer to use the delegate.

The delegate it is the correct and works because i have in the delegate implemented createEditor too and works ok (I have not posted the method because i don't think should be related).

Thanks.