Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QComboBox & QAbstractItemModel - editable/filtering



  • Hey

    What function do I have to implement in my abstract model to allow for filtering to work when I plug the model inside combo box? I'm trying to select item/filter while typing - have auto complete...

    I've set combo->setView(new QTreeView()) as well as combo->setView(new myTree()) neither seem to affect it so it must be model related?

    TIA


    Edit I actually even struggle to get text display in the comboBox line edit from model items... hmmm what do I need to link it properly?


    Did more digging, still no luck, none of signals/slots in QComboWidget return a QModelIndex, thus if I click on item inside another item(child) then I get wrong index. As the index is relevant to rootItem not parentItem... oh dear...

    Trying to get a signal from treeView directly seem to not work either?

        connect(mCombo_scene->view(), &QAbstractItemView::activated, [=](const QModelIndex &index) {
            qDebug() << "EH?  " <<"I got correct Index?";
            //mCombo_scene->setCurrentText(index.data(Qt::DisplayRole).toString());
        });
    

  • Lifetime Qt Champion

    Hi,

    This Wiki entry gives a good starting point.



  • @SGaist Awesome thanks! I think I can get it to do my bad biding now :- )