Rev 145 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
#include <QtGui>#include "textdelegate.h"/*textdelegate.cppA delegate that allows the user to change integer values from the modelusing a line edit widget.*/textDelegate::textDelegate(int maxlen, QObject *parent): QItemDelegate(parent){max_len = maxlen;}QWidget *textDelegate::createEditor(QWidget *parent,const QStyleOptionViewItem &/* option */,const QModelIndex &/* index */) const{QLineEdit *editor = new QLineEdit(parent);editor->setMaxLength(max_len);return editor;}void textDelegate::setEditorData(QWidget *editor,const QModelIndex &index) const{QString value = index.model()->data(index, Qt::EditRole).toString();QLineEdit *lineEditor = static_cast<QLineEdit*>(editor);lineEditor->setText(value);}void textDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,const QModelIndex &index) const{QLineEdit *lineEdit = static_cast<QLineEdit*>(editor);QString value = lineEdit->text();model->setData(index, value, Qt::EditRole);}void textDelegate::updateEditorGeometry(QWidget *editor,const QStyleOptionViewItem &option, const QModelIndex &/* index */) const{editor->setGeometry(option.rect);}