Вроде всё просто решается через QLineEdit обёрнутый в QItemDelegate.
#ifndef CTREEDELEGATE_HPP
#define CTREEDELEGATE_HPP
#include <QItemDelegate>
#include <QRegExpValidator>
#include <QRegExp>
#include <QLineEdit>
class CTreeDelegate : public QItemDelegate
{
Q_OBJECT
public:
CTreeDelegate( QObject * Parent )
: QItemDelegate( Parent ){}
QWidget * createEditor( QWidget * Prent ,
const QStyleOptionViewItem & Option ,
const QModelIndex & Index ) const
{
auto Validator = new QRegExpValidator();
Validator->setRegExp( QRegExp( "^[а-яА-Яa-zA-Z0-9 _-]+" ) );
auto Editor = new QLineEdit( Prent );
Editor -> setValidator( Validator );
return Editor;
}
void setEditorData( QWidget * Editor ,
const QModelIndex & Index ) const
{
auto Value = Index.model() -> data( Index, Qt::EditRole );
auto CastedEditor = static_cast< QLineEdit * >( Editor );
CastedEditor -> setText( Value.toString() );
}
void setModelData( QWidget * Editor ,
QAbstractItemModel * Model ,
const QModelIndex & Index ) const
{
auto CastedEditor = static_cast< QLineEdit * >( Editor );
auto Value = CastedEditor->text();
Model -> setData( Index, Value, Qt::EditRole );
}
void updateEditorGeometry( QWidget * Editor ,
const QStyleOptionViewItem & Option ,
const QModelIndex & Index ) const
{
Editor -> setGeometry( Option.rect );
}
};
#endif /* CTREEDELEGATE_HPP */