문제

QTableWidget have a method to search for a row with user data?

Something like:

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

//find row by user data
int rowIndex = table->findByData("ID001");
도움이 되었습니까?

해결책

You can use 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 ...
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top