QWidget *QgsAttributeTableDelegate::createEditor(
  QWidget *parent,
  const QStyleOptionViewItem &option,
  const QModelIndex &index ) const
{
  Q_UNUSED( option );
  QgsVectorLayer *vl = layer( index.model() );
  if ( !vl )
    return NULL;

  int fieldIdx = index.model()->data( index, QgsAttributeTableModel::FieldIndexRole ).toInt();

  QWidget *w = QgsAttributeEditor::createAttributeEditor( parent, 0, vl, fieldIdx, index.model()->data( index, Qt::EditRole ) );

  if ( parent )
  {
    QgsAttributeTableView *tv = dynamic_cast<QgsAttributeTableView *>( parent->parentWidget() );
    w->setMinimumWidth( tv->columnWidth( index.column() ) );

    if ( vl->editType( fieldIdx ) == QgsVectorLayer::FileName ||
         vl->editType( fieldIdx ) == QgsVectorLayer::Calendar )
    {
      QLineEdit *le = w->findChild<QLineEdit*>();
      le->adjustSize();
      w->setMinimumHeight( le->height()*2 ); // FIXME: there must be a better way to do this
    }
  }

  return w;
}