PDA

View Full Version : moving QTreeWidgetItem



^NyAw^
3rd July 2009, 17:07
Hi,

I have a QTreeWidget that is represented like this:

Column0 Column1
Item1
Item2
|-------------SubItem1 [Button1]
|-------------SubItem2 [Button2]

Internally I have a data structure that contains the same data.
Now, I use a method that let's me move SubItem1 and SubItem2 up or down internally in my structure data. When I finish the internal data moving I want to move the items of the QTreeWidget.
So what I am doing now is to take all the subItems into a QList<QTreeWidgetItem*> and then I reinsert them as Item2 childs following the internal data structure. This works well but there is a problem, all the Widgets that the SubItems have are lost. So the Button1 and Button2 have dissapeared and only the text of the buttons are displayed.

Is there any other way to do this? Or how can I solve this problem?

Thanks,

wysota
3rd July 2009, 17:51
I would suggest switching to the model approach. It's a big step to take at once but you are currently reaching a point when using the simplified interface of QTreeWidget becomes a burden instead of a simplification. If you implement the model correctly, it will work directly on your internal representation and doing such things as moving the items will become a matter of emitting one or two signals and nothing more.

^NyAw^
3rd July 2009, 18:08
Hi,

Thanks wysota. I know that witching to the model approach will be better but currently I can't because I have no much time to spend on this. This is a big application and create the code to make it work on model approach will need much time.

Thanks,

wysota
3rd July 2009, 20:17
It still might require less time than battling against your current architecture.