[PyQt] emit dataChanged not reacted to by QTableView

Barry Scott barry at barrys-emacs.org
Thu Mar 10 12:22:12 GMT 2016


On Tuesday 08 March 2016 16:17:45 Barry Scott wrote:
> I have googled and seen a number of reports that the emit dataChanged is an
> issue for some people.
> 
> But the fixes outlined, add missing roles list, do not work me.
> 
> I am using Python 3.4 on Fedora 23 with Qt 5.5.1 and PyQt 5.5.1.
> 
> The full source of the code I'm see the problem with is in:
> 
> https://github.com/barry-scott/git-workbench/tree/master/Source
> 
> I have the following classes:
> 
> class WbGitTableSortFilter(QtCore.QSortFilterProxyModel):
> 
> class WbGitTableModel(QtCore.QAbstractTableModel):
> 
> class WbTableView(QtWidgets.QTableView):
> 
> self.table_model = wb_git_table_model.WbGitTableModel( self.app )
> self.table_sortfilter = wb_git_table_model.WbGitTableSortFilter( self.app )
> self.table_sortfilter.setSourceModel( self.table_model )
> 
> For debug I connect to dataChanged:
> 
> self.table_model.dataChanged.connect( self.__qqqTableModelDataChanged )
> self.table_sortfilter.dataChanged.connect(
> self.__qqqTableSortFilterDataChanged )
> 
> The code to emit dataChanged is:
> 
> self.dataChanged.emit(
>     self.createIndex( row, 0 ),
>     self.createIndex( row, 4 ) )
> self.dataChanged.emit(
>     self.createIndex( row, 0 ),
>     self.createIndex( row, 4 ),
>     [QtCore.Qt.DisplayRole] )
> 
> (Yes I called it twice in case it mattered about the optional role list).
> 
> When WbGitTableModel is told to update all inserts and removal of
> rows is reflected in the view. But changes in the data are not reflected in
> the TableView.
> 
> I see from debug logs that I emit dataChanged and that the __qqqTablexxx
> functions are called with the expected index values and roles lists.
> 
> DEBUG TABLE-MODEL WbGitTableModel.refreshTable() emit dataChanged row=2
> __qqqTableSortFilterDataChanged( 0-0, 0-4, [] )
> __qqqTableModelDataChanged( 2-0, 2-4, [] )
> __qqqTableSortFilterDataChanged( 0-0, 0-4, [0] )
> __qqqTableModelDataChanged( 2-0, 2-4, [0] )
> 
> Why is QTableView ignoring the dataChanged event?

The answer is I had one code path in the model that fails to save the updated
state. So it did not appear on the screen.

> 
> Barry
> 
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> https://www.riverbankcomputing.com/mailman/listinfo/pyqt



More information about the PyQt mailing list