HELP! QStandardItemModel::findItems(keyword, Qt::MatchContains | Qt::MatchRecursive, column /*= 2*/ )

  • In QTreeView, I cannot use QStandardItemModel::findItems() when search column =2 to search the match items which at column 2.

  • Hi,
    The view should have nothing to do with findItems. Can you show us an example of what you want to happen and what happens instead?

  • @VRonin
    thank you very much!
    I finished it at last by record all the QStandardItem * into a map as below :
    0_1533185159593_02b08c35-56a7-4408-881b-f75abe7c1781-image.png , I can only search the _allItems (which type is: map<QString, QStandardItem *>).

    since QStandardItemModel::findItems () can only search column=0 recursively.

  • @VRonin
    see this link:

    the Qt version is 5.5, as the findItems cannot search column>0 even with Qt::MathRecursive.

  • @Navca-Lin
    not Qt::MathRecursive.

  • Lifetime Qt Champion


    Can you provide a code example that shows how you build and search your model ? I currently don't see any reason why you can't search in any other column than 0, that's just the default value used if you don't pass that parameter.

  • Ok I think I got the problem. All the views in Qt only handle children of items in the first columns while QAbstractItemModel::match it will only search children of the index in column which triggers the clash if column>0. I'd go as far as to say it's an oversight in the code so feel free to post a bug report.

    In the meantime, you can just manually search the model, no need to store the items in a separate map:

    QList<QStandardItem*> findItemsRecurse( QStandardItemModel* model, const QString &text, int column=0, cont QModelIndex& parent = QModelIndex()){
        QList<QStandardItem*> result;
        for(int i=0, maxRow=model->rowCount(parent);i<maxRow;++i){
            QModelIndex currIdx = model->index(i,column,parent);
                result << itemFromIndex(currIdx);
            for(int j=0, maxCol = model->columnCount(parent);j<maxCol;++j){
                currIdx = model->index(i,j,parent);
        return result;

  • @VRonin
    thank you very very very very much~
    I got your code~~

  • @SGaist
    thank you~

    it's like this:




Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.