[PyQt] emit dataChanged not reacted to by QTableView

Barry Scott barry at barrys-emacs.org
Tue Mar 8 16:17:45 GMT 2016


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?

Barry



More information about the PyQt mailing list