Skip to content

Commit

Permalink
Completion of values based on previous entered values in the same column
Browse files Browse the repository at this point in the history
Using the QCompleter class associated to the QLineEdit, an implementation
of a completion of values in the Extended Table Widget is straightforward.
  • Loading branch information
mgrojo authored and MKleusberg committed Sep 28, 2018
1 parent 517743f commit e1101ae
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/ExtendedTableWidget.cpp
Expand Up @@ -19,6 +19,7 @@
#include <QPrinter>
#include <QPrintDialog>
#include <QTextDocument>
#include <QCompleter>

#include <limits>

Expand Down Expand Up @@ -105,10 +106,15 @@ ExtendedTableWidgetEditorDelegate::ExtendedTableWidgetEditorDelegate(QObject* pa
{
}

QWidget* ExtendedTableWidgetEditorDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& /*option*/, const QModelIndex& /*index*/) const
QWidget* ExtendedTableWidgetEditorDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& /*option*/, const QModelIndex& index) const
{
// Just create a normal line editor but set the maximum length to the highest possible value instead of the default 32768.
QLineEdit* editor = new QLineEdit(parent);
QCompleter *completer = new QCompleter(editor);
completer->setModel(const_cast<QAbstractItemModel*>(index.model()));
completer->setCompletionColumn(index.column());
completer->setCompletionMode(QCompleter::InlineCompletion);
editor->setCompleter(completer);
editor->setMaxLength(std::numeric_limits<int>::max());
return editor;
}
Expand Down

0 comments on commit e1101ae

Please sign in to comment.