I need to show some cells in QTableView as QComboBox, even when the tableView no in edit mode. I create my class for it that inherits QStyledItemDelegateClass and reimplement paint method:
Qt Code:
  1. //comboboxdelegate.h
  2. #ifndef COMBOBOXDELEGATE_H
  3. #define COMBOBOXDELEGATE_H
  4.  
  5. #include <QStyledItemDelegate>
  6. #include <QComboBox>
  7.  
  8. class ComboBoxDelegate : public QStyledItemDelegate
  9. {
  10. Q_OBJECT
  11.  
  12. public:
  13. ComboBoxDelegate(QObject *parent = 0);
  14. void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
  15.  
  16. void setItems(const QStringList &itemsList);
  17.  
  18. private:
  19. QStringList m_itemsList;
  20. };
  21.  
  22. #endif // COMBOBOXDELEGATE_H
  23.  
  24. //comboboxdelegate.cpp
  25. #include "comboboxdelegate.h"
  26.  
  27. #include <QComboBox>
  28. #include <QApplication>
  29. ComboBoxDelegate::ComboBoxDelegate(QObject *parent)
  30. : QStyledItemDelegate(parent)
  31. {
  32. }
  33.  
  34. void ComboBoxDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
  35. {
  36. QString value = index.data().toString();
  37. QStyleOptionComboBox comboBoxOption;
  38. comboBoxOption.rect = option.rect;
  39. comboBoxOption.currentText = value;
  40. comboBoxOption.state = QStyle::State_Enabled;
  41. QApplication::style()->drawComplexControl(QStyle::CC_ComboBox, &comboBoxOption, painter);
  42. }
To copy to clipboard, switch view to plain text mode 
but comboBox is not showing in the cells, and data too.
How can I draw the combobox in the cell?