Solve bug of completer in GridAccount

This commit is contained in:
2012-03-11 20:40:07 +01:00
parent c1a612b7ec
commit b114fff9e0
4 changed files with 28 additions and 2 deletions

View File

@@ -53,3 +53,28 @@ void TabDelegate::setEditorData(QWidget *editor,
line->setText(s.trimmed());
}
/*
Implement editorEvent due to a "feature" in Qt : If we have a QLineEdit with a completer
and we press a key on a non edited cell, editor immediatly returns (it's perhaps a focus
problem)
*/
bool TabDelegate::editorEvent ( QEvent * event, QAbstractItemModel * model, const QStyleOptionViewItem & option, const QModelIndex & index )
{
if (event->type() == QEvent::KeyPress && _completer)
{
QTableWidgetItem* item = _grid->item(index.row(), index.column());
if (item->text() == "")
{
_grid->editItem(item);
QLineEdit* line = qobject_cast<QLineEdit *>(_grid->cellWidget(index.row(), index.column()));
QKeyEvent* kevent = dynamic_cast<QKeyEvent *> (event);
line->setText(kevent->text());
_completer->setCompletionPrefix(kevent->text());
_completer->complete();
return true;
}
}
return false;
}