[PyQt] QDirModel instance

Andreas Pakulat apaku at gmx.de
Thu Jul 10 22:08:27 BST 2008


On 10.07.08 11:46:36, Scott Frankel wrote:
>
> Right.  Thanks for pointing out that I still need to explicitly pass  
> "self."
>
> I'm still not getting checkboxes displayed in the tree widget, though.  I 
> believe the problem is in the nested return value in the model's data() 
> method.
>
> The C++ example code I'm following uses a QMap data structure to hold  
> checkState values.  After reading Assistant notes, a python dir(QtCore), 
> and some googling, I've found that QMap is not implemented in PyQt.  So 
> I'm using a Dict instead.  Still, my app complains:
>
> 	TypeError: invalid result type from DirModel.data()
>
>
> Here's the C++ code I'm following:
>
>     virtual QVariant data(const QModelIndex &index, int role =  
> Qt::DisplayRole) const
>     {
>         if (role == Qt::CheckStateRole && index.column() == 0) {
>             return checkstates.value(fileInfo(index).absoluteFilePath(), 
> Qt::Unchecked);

You need to wrap that in a QVariant, i.e. 

return QVariant(....)

data() needs to return a QVariant and Python doesn't support the
implicit constructors as C++ does.

Andreas

-- 
You will pass away very quickly.


More information about the PyQt mailing list