2

QTableWidget 有一种方法可以用用户数据搜索一行吗?

就像是:

//set user data
row->setData(0, Qt::UserRole, "ID001");

//find row by user data
int rowIndex = table->findByData("ID001");
4

1 回答 1

3

您可以使用QAbstractItemModel::match()

QAbstractItemModel *model = table->model();
QModelIndexList matches = model->match( model->index(0,0), Qt::UserRole, "ID001" )

foreach( const QModelIndex &index, matches )
{
    QTableWidgetItem *item = table->item( index.row(), index.column() )
    // Do something with your new-found item ...
}
于 2012-08-07T18:35:28.593 回答