PDA

View Full Version : ComboBox Completer Index Problem



majatu
4th June 2009, 14:09
When i choose something in completer, combobox index does not change. It's changing only when i press enter key. But i want to change index of combo in completer by choosing mouse from popup. How i can do it? Help


QComboBox *cb=new QComboBox();
cb->setModel(this->productModel);
cb->setModelColumn(1);
cb->setEditable(true);
cb->setAutoCompletion(true);
cb->setAutoCompletionCaseSensitivity(Qt::CaseInsensiti ve);

wysota
7th June 2009, 10:21
Connect to the activated() signal of the completer and set the appropriate index of the combobox as the current one.

majatu
7th June 2009, 14:10
Connect to the activated() signal of the completer and set the appropriate index of the combobox as the current one.

thanks for reply, but activated method of completer content index of model, but combobox have setIndex for row only

majatu
7th June 2009, 15:30
solved:

if interesting


void EventDialog::popUpIndex(QModelIndex s)
{
QCompleter * cl = qobject_cast<QCompleter * >(sender());
QComboBox * cb = qobject_cast<QComboBox * >(sender()->parent());

int completer_id=cl->completionModel()->data(cl->completionModel()->index(s.row(),0)).toInt();

QModelIndexList indexList = cb->model()->match(cb->model()->index(0,0), Qt::DisplayRole, completer_id, 1, Qt::MatchExactly);
if(indexList.count())
{
QModelIndex index=indexList.first();
cb->setCurrentIndex(index.row());
}
}