Skip to content

Commit e1101ae

Browse files
mgrojoMKleusberg
authored andcommitted
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.
1 parent 517743f commit e1101ae

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/ExtendedTableWidget.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <QPrinter>
2020
#include <QPrintDialog>
2121
#include <QTextDocument>
22+
#include <QCompleter>
2223

2324
#include <limits>
2425

@@ -105,10 +106,15 @@ ExtendedTableWidgetEditorDelegate::ExtendedTableWidgetEditorDelegate(QObject* pa
105106
{
106107
}
107108

108-
QWidget* ExtendedTableWidgetEditorDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& /*option*/, const QModelIndex& /*index*/) const
109+
QWidget* ExtendedTableWidgetEditorDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& /*option*/, const QModelIndex& index) const
109110
{
110111
// Just create a normal line editor but set the maximum length to the highest possible value instead of the default 32768.
111112
QLineEdit* editor = new QLineEdit(parent);
113+
QCompleter *completer = new QCompleter(editor);
114+
completer->setModel(const_cast<QAbstractItemModel*>(index.model()));
115+
completer->setCompletionColumn(index.column());
116+
completer->setCompletionMode(QCompleter::InlineCompletion);
117+
editor->setCompleter(completer);
112118
editor->setMaxLength(std::numeric_limits<int>::max());
113119
return editor;
114120
}

0 commit comments

Comments
 (0)