1 Attachment(s)
Moving QTreeWidgetItem Up and Down in a QTreeWidget
Hi,
I want to be able to swap two QTreeWidgetItem positions in a QtreeWidget.
With other words move items up and down 1 position in a QtreeWidget.
Attachment 9597
After searching for hours online I just can't find a proper solution.
Not a single one of them works.
Have to add to this that I'm very new to QT.
Does anyone have a solution to my problem?
Thanks in advance.
Re: Moving QTreeWidgetItem Up and Down in a QTreeWidget
You get the parent item, then you call its indexOfChild method to determine the index if your current item, then call takeItem() and then insertItem with either index - 1 or index + 1
Cheers,
_
Re: Moving QTreeWidgetItem Up and Down in a QTreeWidget
Worked as a charm!
Thank you very much.
Code:
int row = this->currentIndex().row();
if (item && row > 0)
{
int index = parent->indexOfChild(item);
parent->insertChild(index-1, child);
parent->setExpanded(true);
child->setExpanded(true);
}