You have mis-implemented rowCount, columnCount, and hasChildren signatures.
They all take an optional parent index parameter which defaults to an
invalid index meaning no parent. So you need to use index=None or
index=QModelIndex() and handle that case.

Some other notes...

You may want to consider not constructing a handful of QIcon instances on
every call to data(). It gets called alot. You can construct them once for
the whole model and share them. Or at least construct them only when it's a
decoration role.

It is usually not a great idea to conditionally set private fields on
classes such at the _node on your item class. That is the reason you have
to handle exceptions later when accessing the name property. Just always
set it to None or some appropriate default value so that your public
members behave properly. Not having a node should still result in some
empty string name.

It might be a good idea to call the super() method at the end of functions
like data() so that you get default behavior for any unhandled cases.

And also, be careful about modifying the underlying parent/child stuff
without informing the model. I know you begin and end row insertion for the
root. I can't remember if it's ok to add tons of children without also
doing nested begin/end row calls. If you end up seeing the initial state of
your view not showing the plus sign for your root nodes then that could be
why (until it calls hasChildren internally later to discover there are
children)

Justin

On Sat, Sep 15, 2018, 5:21 AM kiteh <[email protected]> wrote:

> This is my piece of actual code - https://pastebin.com/pfqDgVtX
>
> As soon as I tried adding the following after Line 292 (after `.setModel`)
> for row in range(self.tree_view.rowCount()):
>     data.append([])
> for column in range(self.tree_view.columnCount()):
>     index = self.tree_view.index(row, column)
>   data[row].append(str(self.tree_view.data(index).toString()))
>
> I got this error:
> # TypeError: rowCount() takes exactly 2 arguments (1 given) #
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/2c10335c-874c-494d-820f-7142980d725a%40googlegroups.com
> <https://groups.google.com/d/msgid/python_inside_maya/2c10335c-874c-494d-820f-7142980d725a%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA0qSrUOavpSYbq5Tn9nRkFqqnQeCFjK55wPBrbMn-U64Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to