sgroarke
12th June 2007, 14:17
I think this a newbie question - I'm new to QT anyway...
I'm writing in Python, although I strongly suspect the solution to my problem is generic QT rather than Python-specific, so feel free to answer in C++.
I have a populated QListView. All items are top-level, so there are no parents/children.
I want to walk down the QListView and based upon a condition make some entries children, although only ever one-generation deep.
For example, if I have 10 (top level) items in my list to start, I wish (for example) to set items 2 - 4 to all be children of 1, 6 to be a child of 5, 8 - 10 to be children of 7.
So I end up with 3 top level items: 1, 5 & 7.
I'm sure it's trivially easy but I just can't do it!
The obvious (seeming) solution was to use a QListViewItemIterator to walk down the list and selectively takeItem and then insertItem.
Yet when I do this things go very awry - I'm guessing that taking items out of the list over which you are running an iterator is causing confusion...? Anyway, I can't get it to work for me!
So if anyone could outline how to achieve it (Python ideal, but C++, pseudo code, etc. all appreciated!!) I'd be very grateful. I'm sure I'm not the first person to want to do it, but I've searched high and low and cannot find an answer.
Sean
I'm writing in Python, although I strongly suspect the solution to my problem is generic QT rather than Python-specific, so feel free to answer in C++.
I have a populated QListView. All items are top-level, so there are no parents/children.
I want to walk down the QListView and based upon a condition make some entries children, although only ever one-generation deep.
For example, if I have 10 (top level) items in my list to start, I wish (for example) to set items 2 - 4 to all be children of 1, 6 to be a child of 5, 8 - 10 to be children of 7.
So I end up with 3 top level items: 1, 5 & 7.
I'm sure it's trivially easy but I just can't do it!
The obvious (seeming) solution was to use a QListViewItemIterator to walk down the list and selectively takeItem and then insertItem.
Yet when I do this things go very awry - I'm guessing that taking items out of the list over which you are running an iterator is causing confusion...? Anyway, I can't get it to work for me!
So if anyone could outline how to achieve it (Python ideal, but C++, pseudo code, etc. all appreciated!!) I'd be very grateful. I'm sure I'm not the first person to want to do it, but I've searched high and low and cannot find an answer.
Sean