[PyQt] Bugs galore in QAbstractTableModel???
Vicent Mas
uvemas at gmail.com
Sun Nov 28 10:54:19 GMT 2010
2010/11/28 Andreas Pakulat <apaku at gmx.de>:
> 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 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
viceversa :-). 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.
More information about the PyQt
mailing list