Solve bug of completer in GridAccount

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

View File

@ -225,7 +225,7 @@ void GridAccount::LoadOperations(std::vector<Operation>* operations, int month,
_kiss->GetHistory(month, year, list);
_completer = new QCompleter(list);
_completer->setCaseSensitivity(Qt::CaseInsensitive);
_completer->setCompletionMode(QCompleter::InlineCompletion);
//_completer->setCompletionMode(QCompleter::InlineCompletion);
}
TabDelegate* descriptionEditor = new TabDelegate(this, &_displayedOperations, _completer);

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;
}

View File

@ -37,6 +37,7 @@ public:
void setEditorData(QWidget *editor, const QModelIndex &index) const;
void setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const;
bool editorEvent ( QEvent * event, QAbstractItemModel * model, const QStyleOptionViewItem & option, const QModelIndex & index );
private:
std::vector<Operation>* _operations;

View File

@ -25,7 +25,7 @@
class TableViewDelegate : public QStyledItemDelegate
{
private:
protected:
GridAccount* _grid;
public: