View Full Version : QSortFilterProxyModel with QComboBox

10th June 2009, 12:31
Can you please let me know how to use QSortFilterProxyModel with QComboBox, for hiding or showing any item in combobox.
Thank you in advance.

10th June 2009, 20:16
There's no direct relation between QComboBox and QSortFilterProxyModel.
QComboBox can serve as an item delegate in an item view (QTreeView, QTableView) to give the user a choice for data entry.

You will find more about item delegates in the Qt documentation.

Just to give an idea how it works. If the item delegate (in thie example a class with name "IemDelegate") is registered with a view the "createEditor" method is called from the view when needed to give user the option to enter a value from the combo box:

QWidget* ItemDelegate::createEditor(QWidget* parent,
const QStyleOptionViewItem& option,
const QModelIndex& index) const
QComboBox* editor = new QComboBox(parent);

editor->addItem("Entry 1");
editor->addItem("Entry 2");
editor->addItem("Entry 3");

return editor;

Since the "createEditor" method gets the QModelIndex for the data to be edited you can access the related model if really necessary:


If your view has a QSortFilterProxyModel attached then the model returned above is exactly this.