PDA

View Full Version : find item in QListView



AD
14th November 2008, 12:21
I want to get the index of item of QListView and set at this item focus. The items are strings! How can I make it?

I have made this is:


void LicenceBuilder::findLeftSN(const QString& new_SN)
{
if(new_SN.isEmpty()) return;

QSqlTableModel model;
model.setTable("DeviceList");
model.select();
QStringList listNames, selList;
for(int i=0; i<model.rowCount(); ++i)
{
QSqlRecord record = model.record(i);
listNames.append(record.value("serialNumber").toString());
}
foreach(QString name, listNames)
if(name.indexOf(new_SN, 0, Qt::CaseInsensitive) != -1)
selList.append(name);

/// What to do??????
}


This slot must find index of item and set focus. Help me, please!

caduel
14th November 2008, 13:15
have you had a look at QAbstractItemModel::match()?

AD
14th November 2008, 13:25
Thanks! I try :)

AD
14th November 2008, 13:50
GREAT THANKS! It helped me. This code resolve this problem:


/// Поиск в левом списке номера, часть (или он весь) которого отражена в new_SN
void LicenceBuilder::findLeftSN(const QString& new_SN)
{
// after phrase What to do??????

QModelIndexList indexList = model.match(model.index(0, 0), Qt::DisplayRole, selList.first());
QModelIndex selectedIndex(indexList.first());
listDBNumbers -> setCurrentIndex(selectedIndex);
}