Hi, I am using a custom ItemDelegate with a QTreeView. The editor widget that the ItemDelegate provides is one that resizes itself dynamically, and I would like to have its size affect the size of the TreeView cell holding the widget.

I am using ItemDelegate::sizeHint() to control the size of each cell, but it appears that sizeHint() is never called when the editor widget is active, even if I explicitly emit the sizeHintChanged() signal.

Here's a snip of the relevant code:

Qt Code:
  1. QSize MyItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
  2. {
  3. if (_view->indexWidget(index))
  4. // return the size hint of the active editor widget
  5. return _view->indexWidget(index)->sizeHint();
  6. return QItemDelegate::sizeHint(option, index);
  7. }
  8.  
  9. QWidget *MyItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
  10. {
  11. AutoExpandingTextEdit *editor = new AutoExpandingTextEdit(parent, index);
  12. connect(editor, SIGNAL(autoExpanded(const QModelIndex &)), this, SIGNAL(sizeHintChanged(const QModelIndex &)));
  13. return editor;
  14. }
To copy to clipboard, switch view to plain text mode 

The AutoExpandingTextEdit is just a custom QTextEdit widget that resizes itself as the user types. Each time it resizes, it emits the autoExpanded signal. I have verified that this is successfully triggering the sizeHintChanged signal, however the sizeHintChanged signal is not causing the sizeHint method to execute when the editor is active.

Any ideas?