[Qt-interest] QComboBox and QSortFilterProxyModel

Bo Thorsen bo at fioniasoftware.dk
Thu May 26 15:35:37 CEST 2011


Den 26-05-2011 13:53, David Heremans skrev:
> Hello,
>
> I have a custom datamodel (derived from QAbstractTableModel) with a few
> columns representing a guid, type, description,...
>
> I want the user to select items based on a description but filtered out
> by type, so I instantiated a QSortFilterProxyModule and hooked this one
> up to a QComboBox.
>
> It seems that from the combobox I can get the numerical index or the
> QString that is displayed by the combobox, but is there a way to
> retrieve the QModelIndex of the selected item ?
> Or do I really need to iterate over my data using a 'QVariant data(const
> QModelIndex&index, int role) const;' method to compare the the values
> one by one?

You can call sourceModel() to get the original model and mapToSource() 
to get the index for it.

Bo Thorsen,
Fionia Software.

-- 

Expert Qt and C++ developer for hire
Contact me if you need expert Qt help
http://www.fioniasoftware.dk



More information about the Qt-interest-old mailing list