Solve bug of completer in GridAccount
This commit is contained in:
parent
c1a612b7ec
commit
b114fff9e0
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
class TableViewDelegate : public QStyledItemDelegate
|
||||
{
|
||||
private:
|
||||
protected:
|
||||
GridAccount* _grid;
|
||||
|
||||
public:
|
||||
|
|
Loading…
Reference in New Issue
Block a user