Hi, is there a way to filter out repeated strings when using a QSqlTableModel, in a QTableView as the model for a completer?
As an example, if I have a column, FirstName, that the completer is getting the list from, and there are 4 instances of Mark, I am currently getting 4 options for Mark in the popup. I would only like it to show one. Using inline, somewhat solves that, as I have it implemented below, but the popup option works better for my purposes. I have not tried, but it seems like inline does not correct for using lowercase when using that option, which would just add even more instances, assuming the database does not care about case. The only other alternative I can think of is to create a list, for each column, and apply that individually, according to the column being edited, which pretty much defeats the advantages of using a model.
If it helps, my delegate is created like this
{
completer->setModel(model);
completer
->setCompletionMode
(QCompleter::InlineCompletion);
completer->setCaseSensitivity(Qt::CaseInsensitive);
completer->setCompletionColumn(index.column());
editor->setCompleter(completer);
return editor;
}
QWidget *Delegate::createEditor(QWidget *parent,
const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
QLineEdit *editor = new QLineEdit(parent);
QCompleter *completer = new QCompleter(editor);
completer->setModel(model);
completer->setCompletionMode(QCompleter::InlineCompletion);
completer->setCaseSensitivity(Qt::CaseInsensitive);
completer->setCompletionColumn(index.column());
editor->setCompleter(completer);
return editor;
}
To copy to clipboard, switch view to plain text mode
I get the model this way
{
this->model = model;
}
Delegate::Delegate(QSqlTableModel *model, QObject *parent) :
QItemDelegate(parent)
{
this->model = model;
}
To copy to clipboard, switch view to plain text mode
and the model, in mainWindow
model->setTable("Component");
model->select();
ui->dataView->setModel(model);
ui->dataView->hideColumn(0);
ui->dataView->setSortingEnabled(true);
ui->dataView->setAlternatingRowColors(true);
delegate = new Delegate(model, this);
ui->dataView->setItemDelegate(delegate);
model = new QSqlTableModel(this);
model->setTable("Component");
model->select();
ui->dataView->setModel(model);
ui->dataView->hideColumn(0);
ui->dataView->setSortingEnabled(true);
ui->dataView->setAlternatingRowColors(true);
delegate = new Delegate(model, this);
ui->dataView->setItemDelegate(delegate);
To copy to clipboard, switch view to plain text mode
It might just be something simple I am overlooking, but I would appreciate any suggestions.
Bookmarks