Make QCompleter search in QStandardItemModel “data” instead “text”
Make QCompleter search in QStandardItemModel “data” instead “text”
I am using a QCompleter
with a QStandardItemModel
as a model.
QCompleter
QStandardItemModel
The code goes something like this:
QStandardItemModel *modelProtocolName = new QStandardItemModel();
QStringList list;
list << "one" << "two" << "three";
for (int i = 0; i < list.length(); i++)
QStandardItem *item = new QStandardItem();
item->setText( list.at( i ) );
item->setData( "real one, two or three is inserted here", ZAdvancedCompleter::CompleteRole );
modelProtocolName->appendRow( item );
ZAdvancedCompleter completerProtocolName = new ZAdvancedCompleter( this );
completerProtocolName->setModel( modelProtocolName );
Now when I use the QCompleter
it searches in the list, i.e. in "one", "two" and "three". Is it possible to direct the search to the data of the model?
QCompleter
Actually I've read this and it works so far that the correct value (from data) is put into the QLineEdit after selection. But during typing it still searches in text and not in data, any idea how this can be fixed?
– yvesonline
Feb 22 '13 at 12:34
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Check this: stackoverflow.com/a/14373930/1465625
– hank
Feb 22 '13 at 12:29