Hi, I need to create a QItemDelegate in a QTableWidget cell, that would be QLineEdit in that particular cell. On that cell I need to install a QCompleter object. Thus, I subclass the QItemDelegate with my class and reimplement the virtual createEditor() method this way:

Qt Code:
  1. QWidget *ProductsDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &/* option */,
  2. const QModelIndex &/* index */) const
  3. {
  4. QLineEdit *productsEditor = new QLineEdit(parent);
  5. QCompleter *productsCompleter=new QCompleter();
  6.  
  7. QSqlQueryModel *sqlProductsQuery=new SqlQueryModel(productsCompleter);
  8. sqlProductsQuery->setQuery("SELECT product_name FROM jeam_products");
  9. productsCompleter->setModel(sqlProductsQuery);
  10.  
  11. productsEditor->setCompleter(productsCompleter);
  12.  
  13. return productsEditor;
  14. }
To copy to clipboard, switch view to plain text mode 
Then I install the delegate in the column in the QTableWidget object with QTableWidget::setItemDelegateForColumn(...) method.

This creates the delegate fine. When I double click the cell it opens the line edit and when I press "A" it reads from the database and shows popup with completion recomendations. I have enabled all EditTriggers for the table, because basically I need all of them. That means that the AnyKey edit trigger is also enabled. So i set the focus on the cell on which the delegate is installed and type the letter (for i.e.) 'A'. If the SqlQuery finds entry in the database that starts with A, the cell immediatelly opens and closes, it loses focus and the delegate closes/destroys itself. The delegate opens for editing only if I have set the QCompleter::InlineCompletion CompletionMode or if there is no such entry in the database (ie. if I type 'W' and there is no entry that starts with 'W' in the db table).

This is very strange and I hoped I did everything right ...
Any ideas and answers would be very much appreciated.

thanks