Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
QComboBox with QSortFilterProxyModel as a model.
bsomervi last edited by
I have several custom models which I wrap with QSortFilterProxyModel to save me having to implement ordering constraints in my models. All I have to do is issue a sort key in their data() method under a custom user role. This is great and a big time saver since I don't have to do any of the persistent model index accounting involved with "editable and sortable" custom models. I want to use a column of these models as a model in a QComboBox (think choosing a foreign key value in database terminology).
My problem is that neither QComboBox nor it's internal view class seem to respond to the model signals that are issued by QSortFilterProxyModel when it sorts the proxy. I'm sure I'm missing something obvious since the QComboBox responds to row/column adds and removes but I can't find out how to make it respond to row/column moves and layout change signals.
If I sort the proxy model column manually by calling sort before setting the QComboBox model everything is fine until the proxy changed elsewhere, the sort order breaks down in the QComboBox popup list.
I've tried turning off dynamic sorting and filtering and calling sort() on the proxy model myself when it gets changed, that works fine with other views of it like QTableView but the QComboBox popup list reverts to some seemingly random ordering.
Is this a deficiency in QComboBox?