Good day friends!

I'm trying to customize a QTableView through QItemDelegate. Trying debug noticed that my class MyDelegate is not being processed. I ask: Is it possible to delegate with QSqlQueryModel? What may be occurring's wrong? Follow my code:

Qt Code:
  1. void CadComissoes::getUsuarios()
  2. {
  3. OpenDB();
  4. QSqlQuery qry;
  5. QString SQL;
  6.  
  7. model = new QSqlQueryModel();
  8.  
  9. SQL = "SELECT COD_USER, NAME, COD_GROUP ";
  10. SQL+= "FROM USERS";
  11.  
  12. qry.prepare(SQL);
  13. qry.exec();
  14.  
  15. model->setQuery(qry);
  16. ui.tableView_ComissaoUsuarios->setModel(model);
  17.  
  18. MyDelegate *iDelegate = new MyDelegate(this);
  19. ui.tableView_ComissaoUsuarios->setItemDelegate(iDelegate);
  20. CloseDB();
  21. }
  22.  
  23. MyDelegate::MyDelegate(QObject *parent)
  24. :QItemDelegate(parent)
  25. {
  26.  
  27. }
  28.  
  29. QWidget *MyDelegate::createEditor(QWidget *parent,
  30. const QStyleOptionViewItem &option,
  31. const QModelIndex &index) const
  32. {
  33. if (!index.isValid())
  34. {
  35. qDebug() << "Not Valid index";
  36. }
  37. if (index.column() == 2)
  38. {
  39. QSpinBox *editor = new QSpinBox(parent);
  40. editor->setMinimum(0);
  41. editor->setMaximum(100);
  42. return editor;
  43. }
  44. }
  45.  
  46. void MyDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
  47. {
  48. int value = index.model()->data(index, Qt::DisplayRole).toInt();
  49.  
  50. QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
  51. spinBox->setValue(value);
  52. }
  53.  
  54. void MyDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
  55. const QModelIndex &index) const
  56. {
  57. QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
  58. spinBox->interpretText();
  59. int value = spinBox->value();
  60.  
  61. model->setData(index, value, Qt::EditRole);
  62. }
To copy to clipboard, switch view to plain text mode 

Thanks,

Marcelo E. Geyer