gpt4 book ai didi

QTableWidget 通过userdata找一行

转载 作者:行者123 更新时间:2023-12-04 05:36:32 30 4
gpt4 key购买 nike

QTableWidget 有搜索用户数据行的方法吗?

类似的东西:

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

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

最佳答案

您可以使用 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 ...
}

关于QTableWidget 通过userdata找一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11851854/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com