mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 11:00:44 -06:00
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.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user