Hi Jun,

to be consistent the addData() method should accept your data and the
parent QModelIndex where the data will be added, so the method
signature will be something like addData(data, parent=QModelIndex()).
By convention an invalid QModelIndex represent the root item of a tree
view.

The return value of addData should be the QModelIndex instance which
points to your data, so you can call again the addData() method
passing the new data as the parent.

Talking about code:

...
index1 = model.addData(data1)  # Add data to the root item and return
the QModelIndex instance
index2 = model.addData(data2, parent=index1)  # Add data as child of
the previously added data

Read carefully the docs about the QModelIndex here
http://www.pyside.org/docs/pyside/PySide/QtCore/QModelIndex.html
because it's very important when working with models and views. And
QAbstarctItemModel too
http://www.pyside.org/docs/pyside/PySide/QtCore/QAbstractItemModel.html
.


On 8 February 2012 03:53, Jun Koi <junkoi2...@gmail.com> wrote:
> On Tue, Feb 7, 2012 at 10:22 PM, Aaron Richiger <a.ri...@bluewin.ch> wrote:
>> Hello Jun!
>>
>> As other suggested, model.rowsInserted(parent, start, end).emit() is the
>> signal you need. To show you the way one could do this, I shortly changed
>> the Simple Tree View example of PySide (quick and dirty, I know, but it
>> shows enough)... You may add new items filling in the LineEdits and then
>> clicking the button. The only magic line is the last one of the method
>> TreeModel.addData().
>>
> .....
>>    model = TreeModel(rootItem)
>>    model.addData(data, rootItem)
>
> with this awesome demo, i can add a new data to the view with
> TreeModel.addData(), like in the code you wrote above.
>
> for example, i created a new tree node like this:
>
> ....
> NewData
>
>
> now, if i want to create a subnode for NewData, so it will be like this:
>
> ....
> NewData
>    |____ MyChildData
>
>
> i guess to do that, again i need to use TreeModel.addData(), but the
> difference is that this time i need the model of NewData, so it will
> create a subnode, but not the model of the TreeView (the root) like
> when i created NewData
>
> so the question is: how can i get the model of the NewData i created above?
> (i suppose that i need to modify the addData() function, so it returns
> the model of the newly created node, but i have no idea how to do
> that)
>
> thanks a lot,
> Jun
> _______________________________________________
> PySide mailing list
> PySide@lists.pyside.org
> http://lists.pyside.org/listinfo/pyside



-- 
Daniele Esposti

My Blog http://www.expobrain.net
LinkedIn http://www.linkedin.com/in/danieleesposti
Twitter http://www.twitter.com/#!/expobrain
_______________________________________________
PySide mailing list
PySide@lists.pyside.org
http://lists.pyside.org/listinfo/pyside

Reply via email to