Hello All

I have created a QLineEdit delegate to add it to TreeView, the source code is done using the spinbox delegate example.
What I want is to get the value of that line edit box. I cant seem to get the correct value. I always get the one before the last value.

My questions is HOW to update the control so I can get the current value that the user presses Enter?

Below is the class for the LineEditDelegate, and also for the getValue slot in Mycalss


Qt Code:
  1. LineEditDelegate::LineEditDelegate(QObject *parent, Myclass* mc)
  2. : QItemDelegate(parent), m_mc(mc)
  3. {
  4. }
  5.  
  6. QWidget *LineEditDelegate::createEditor(QWidget *parent,
  7. const QStyleOptionViewItem &/* option */,
  8. const QModelIndex &/* index */) const
  9. {
  10. QLineEdit *editor = new QLineEdit(parent);
  11.  
  12. connect(editor, SIGNAL(returnPressed()), m_mc, SLOT(getValue() ) );
  13.  
  14. //connect(editor, SIGNAL(textChanged(QString)), editor, SLOT(setText(QString)) );
  15.  
  16. return editor;
  17. }
  18.  
  19. void LineEditDelegate::setEditorData(QWidget *editor,
  20. const QModelIndex &index) const
  21. {
  22. QString value = index.model()->data(index, Qt::EditRole).toString();
  23.  
  24. QLineEdit *lineEdit = static_cast<QLineEdit*>(editor);
  25. lineEdit->setText(value);
  26. }
  27.  
  28. void LineEditDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
  29. const QModelIndex &index) const
  30. {
  31. QLineEdit *lineEdit = static_cast<QLineEdit*>(editor);
  32. double value = lineEdit->text().toDouble();
  33.  
  34. model->setData(index, value, Qt::EditRole);
  35. }
  36.  
  37. void LineEditDelegate::updateEditorGeometry(QWidget *editor,
  38. const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
  39. {
  40. editor->setGeometry(option.rect);
  41. }
To copy to clipboard, switch view to plain text mode 



Qt Code:
  1. void getValue(){
  2. QModelIndex index = m_view->currentIndex();
  3. double size = m_view->model()->data(index, Qt::DisplayRole).toDouble();
  4.  
  5. //The size is ALWAYS the older value, not the last one
  6. QMessageBox::information(0, "value", QString("%1").arg(size));
  7. }
To copy to clipboard, switch view to plain text mode 

Any comment is more than welcome

Thanks all