C++ 查找包含值的单元格的索引并在QTableView中高亮显示所有这些单元格 在QTabLeVIEW中找到包含qSql的单元格的索引(即行数和列号)?
(注意:无需单击qtableview中的单元格)您可以使用C++ 查找包含值的单元格的索引并在QTableView中高亮显示所有这些单元格 在QTabLeVIEW中找到包含qSql的单元格的索引(即行数和列号)?,c++,qt,qtableview,qstring,C++,Qt,Qtableview,Qstring,(注意:无需单击qtableview中的单元格)您可以使用findItems()函数查找您的单元格 findItems()函数在给定列中使用给定标志返回与给定文本匹配的项列表 for (int index = 0; index < model->columnCount(); index++) { QList<QStandardItem*> foundLst = model->findItems("YourText", Qt::MatchExactly, in
findItems()
函数查找您的单元格
findItems()
函数在给定列中使用给定标志返回与给定文本匹配的项列表
for (int index = 0; index < model->columnCount(); index++)
{
QList<QStandardItem*> foundLst = model->findItems("YourText", Qt::MatchExactly, index);
}
for(int index=0;indexcolumnCount();index++)
{
QList foundLst=model->findItems(“YourText”,Qt::matchjustice,index);
}
如果要获取找到的项的索引并突出显示它,请使用以下代码:
for (int index = 0; index < model->columnCount(); index++)
{
QList<QStandardItem*> foundLst = model->findItems("YourText", Qt::MatchExactly, index);
int count = foundLst.count();
if(count>0)
{
for(int k=0; k<count; k++)
{
QModelIndex modelIndex = model->indexFromItem(foundLst[k]);
qDebug()<< "column= " << index << "row=" << modelIndex.row();
((QStandardItemModel*)modelIndex.model())->item(modelIndex.row(),index)->setData(QBrush(Qt::green),Qt::BackgroundRole);
}
}
}
for(int index=0;indexcolumnCount();index++)
{
QList foundLst=model->findItems(“YourText”,Qt::matchjustice,index);
int count=foundLst.count();
如果(计数>0)
{
对于(int k=0;kindexFromItem(foundLst[k]);
qDebug()您的意思是在表中搜索并查找值?搜索后,我想知道值在表中的位置,我会更新我的答案。这一行添加了:((QStandardItemModel*)modelIndex.model())->item(modelIndex.row(),index)->setData(QBrush(Qt::green),Qt::BackgroundRole);