Hi, originally I posted this question the the long thread "Bugs galore in QAbstractTableModel" but I'm suspicious the question has just been missed because I got no answer and that thread seems now mainly devoted to modtest.py So I've decided to resend my question with a new Subject. I hope I'm not being too impatient.
2010/11/28 Andreas Pakulat <[email protected]>: > On 27.11.10 21:27:55, Ian wrote: > [...] > >> def rowCount(self, parent = None): >> ''' return No of rows of data. parent is a QModelIndex ''' >> return len(self.view) > > This is wrong, even for table models you have to take care to return the > right number of rows depending on the parent. That means if your model > gets asked for the rowCount with a valid parent, you want to return 0 > (as you don't have childs under any of your rows). So check for > parent.isValid(). > >> def columnCount(self, parent = None): >> ''' return number of columns. parent = QModelIndex() >> id, name, cubref, address, town, contacts >> ''' >> return 6 > > Basically the same here as above, though I think this is not quite as > critical. > Hi Andreas, Are you sure about this? Does it mean that the example given in the page 428 of Summerfield's book "Rapid GUI Programming with Python and Qt" is wrong? Also I find misleading the Qt documentation regarding this subject (right now I can only have a look to the Qt-6 docs). On one side the QAbstractItemModel.rowCount documentation agrees with you (or vice versa :-). But reading the "Model Subclassing Reference" page, section "Read-only access" one can see: " rowCount() Provides the number of rows of data exposed by the model. These four functions must be implemented in all types of model, including list models (QAbstractListModel subclasses) and table models (QAbstractTableModel subclasses). Additionally, the following functions must be implemented in direct subclasses of QAbstractTableModel and QAbstractItemModel: columnCount() Provides the number of columns of data exposed by the model. List models do not provide this function because it is already implemented in QAbstractListModel. " Sorry if I'm missing something obvious (it wouldn't be the first time that I've issues with the Qt documentation regarding models and views). Vicent :: Share what you know, learn what you don't
signature.asc
Description: This is a digitally signed message part.
_______________________________________________ PyQt mailing list [email protected] http://www.riverbankcomputing.com/mailman/listinfo/pyqt
