
tData(model.index(0, self.COL_ID), personID) tHeaderData(self.COL_NAME, QtCore.Qt.Horizontal, "Name")ĭef addPerson(self, model, personID, personName): tHeaderData(self.COL_ID, QtCore.Qt.Horizontal, "ID") Model = QtGui.QStandardItemModel(0, 2, parent) (QtCore.QModelIndex(), QtCore.QModelIndex()) Self.resize(800,450) # resize main windowĬon.execute("create table person(id int, name text)")Ĭon.execute("insert into person(id, name) values (1, 'anders')") Ĭon.execute("insert into person(id, name) values (2, 'Arachno')") Ĭon.execute("insert into person(id, name) values (3, 'Zabel')") Ĭon.execute("insert into person(id, name) values (4, 'Ötztürk')") Ĭon.execute("insert into person(id, name) values (5, 'de Hahn')") tWindowTitle("PyQt5 QTreeView refresh problem demo") 圜olumn(self.COL_ID, QtCore.Qt.AscendingOrder)

Return super(HumanProxyModel, self).lessThan(source_left, source_right) Return _human_key(data_left) < _human_key(data_right) If type(data_left) = type(data_right) = str:

Parts = re.split(r'(\d*\.\d+|\d+)', key, re.IGNORECASE)Ĭlass HumanProxyModel(QtCore.QSortFilterProxyModel):ĭef lessThan(self, source_left, source_right):
#PYQT5 TREEVIEW UPDATE#
nothing.Ĭan I somehow tell my model to refresh or update the data, without fetching alls rows again?įrom PyQt5 import QtWidgets, QtCore, QtGui

One way to do this would be to build up my complete model and refetch all rows, but then the user-selected cell disappears and it is very slow and also the TreeView flickers (because I do some column adjustings concerning the width.)Įmiting dataChanged signal on the QSortFilterProxyModel somehow seems to do. Now I would like to refresh the changed data from the database. On closing the edit-dialog the focus gets back to the underlying QTreeView. With a double-click I am executing a modal QDialog to edit the data (the user can do CRUD operations like create new rows into my SQLite data base, updates, delete etc.). I am displaying rows from the database here. I have a model-based QTreeView which is fed by a QSortFilterProxyModel.
