Permalink
Browse files

Completion of values based on previous entered values in the same column

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 Aug 24, 2018
1 parent 517743f commit e1101ae6905130dd4d7becf323303a4ae804d99f
Showing with 7 additions and 1 deletion.
  1. +7 −1 src/ExtendedTableWidget.cpp
@@ -19,6 +19,7 @@
#include <QPrinter>
#include <QPrintDialog>
#include <QTextDocument>
#include <QCompleter>

#include <limits>

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

0 comments on commit e1101ae

Please sign in to comment.