Reputation: 15
I've got a QTableView that uses a combobox delegate in 2 of the table's columns. The selected item from the combobox displays in the TableView correctly if no columns are sorted. When a column is sorted, the selected item does not display in the TableView.
The dataframe model in the delegate reflects the current sorted data in the TableView. The dataframe in the PythonModel reflects the original unsorted dataframe. How do I get the dataframes to sync after a column is sorted?
self.model = PandasModel(self.df_referrals)
self.proxyModel = MySortFilterProxyModel()
self.proxyModel.setSourceModel(self.model)
self.table_view.setSortingEnabled(True)
self.table_view.setModel(self.proxyModel)
self.table_view.setItemDelegate(EscapeDelegate(self.model))
self.filter_referrals.textChanged.connect(self.proxyModel.setSearchText)
self.area_delegate = ComboBoxDelegate(self.area_list, self.model)
self.county_delegate = ComboBoxDelegate(self.county_dict, self.model)
self.table_view.setItemDelegateForColumn(4, self.area_delegate)
self.table_view.setItemDelegateForColumn(5, self.county_delegate)
Upvotes: 0
Views: 16
Reputation: 15
The problem was in the setData function of my PandasModel. I was using values instead of iloc.
self.data_frame.iloc[index.row(), index.column()] = value
Upvotes: 0