遍历Qt treeWidget,查找指定字段内容的条目,并跳转到该条目。
void MainWindow::on_pushButton_sidFind_clicked()
{QString sid = ui->lineEdit_sidFind->text();QTreeWidgetItemIterator it(ui->treeWidget_sqItem);while (*it) {if ((*it)->text(0).contains(sid)){/*! diselect all */QTreeWidgetItemIterator item(ui->treeWidget_sqItem);while (*item) {(*item)->setSelected(false);++item;}/*! set current selected */ui->treeWidget_sqItem->setCurrentItem(*it);break;}++it;}ui->treeWidget_sqItem->scrollToItem(ui->treeWidget_sqItem->currentItem());
}