Yes, everything works fine if I do not use setItemDelegate. I overrode createEditor, setEditor, setModelData, and updateModelGeometry. As I said before, my code works fine by itself, just not inside my db program.

Applying the delegate:
Qt Code:
  1. if(viewInit)
  2. {
  3. model->submitAll();
  4. delete model;
  5. }
  6. int rowCount = 0;
  7. model = new QSqlTableModel();
  8. model->setTable(tableName);
  9. model->setEditStrategy(QSqlTableModel::OnManualSubmit);
  10. model->select();
  11. model->removeColumn(8);
  12. rowCount = model->rowCount();
  13. ui.tableTV->setModel(model);
  14. checkboxDelegate delegate;
  15. ui.tableTV->setItemDelegate(&delegate);
  16. ui.tableTV->resizeColumnToContents(2);
  17. ui.tableTV->hideColumn(0);
  18. ui.tableTV->setEditTriggers(QAbstractItemView::CurrentChanged);
  19. ui.tableTV->setAlternatingRowColors(true);
  20. ui.tableTV->scrollToBottom();
To copy to clipboard, switch view to plain text mode 

The delegate:
Qt Code:
  1. checkboxDelegate::checkboxDelegate(QObject *parent)
  2. : QItemDelegate(parent)
  3. {
  4. }
  5.  
  6. QWidget *checkboxDelegate::createEditor(QWidget *parent,
  7. const QStyleOptionViewItem &option,
  8. const QModelIndex &index) const
  9. {
  10. if(index.isValid() && index.column() == checkboxCol)
  11. {
  12. QCheckBox *editor = new QCheckBox(parent);
  13. editor->installEventFilter(const_cast<checkboxDelegate*>(this));
  14. return editor;
  15. }
  16. else
  17. {
  18. return QItemDelegate::createEditor(parent, option, index);
  19. }
  20. }
  21.  
  22. void checkboxDelegate::setEditorData(QWidget *editor,
  23. const QModelIndex &index) const
  24. {
  25. if(index.isValid() && index.column() == checkboxCol)
  26. {
  27. QString value = index.model()->data(index, Qt::DisplayRole).toString();
  28.  
  29. QCheckBox *checkBox = static_cast<QCheckBox*>(editor);
  30. if(value == "Y")
  31. checkBox->setCheckState(Qt::Checked);
  32. else
  33. checkBox->setCheckState(Qt::Unchecked);
  34. }
  35. else
  36. {
  37. QItemDelegate::setEditorData(editor, index);
  38. }
  39. }
  40.  
  41. void checkboxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
  42. const QModelIndex &index) const
  43. {
  44. if(index.isValid() && index.column() == checkboxCol)
  45. {
  46. QCheckBox *checkBox = static_cast<QCheckBox*>(editor);
  47. QString value;
  48. if(checkBox->checkState() == Qt::Checked)
  49. value = "Y";
  50. else
  51. value = "N";
  52.  
  53. model->setData(index, value);
  54. }
  55. else
  56. {
  57. QItemDelegate::setModelData(editor, model, index);
  58. }
  59. }
  60.  
  61. void checkboxDelegate::updateEditorGeometry(QWidget *editor,
  62. const QStyleOptionViewItem &option, const QModelIndex &index) const
  63. {
  64. if(index.isValid() && index.column() == checkboxCol)
  65. editor->setGeometry(option.rect);
  66. else
  67. QItemDelegate::updateEditorGeometry(editor, option, index);
  68.  
  69. }
To copy to clipboard, switch view to plain text mode