Raise and lower QTreeWidgetItem in a QTreeWidget?

pyqt, python, qt, qtreewidget

Solution

I believe you would need to use model object to be able to manipulate items positions (if this what you want to do). Please check an example below; it moves the first item of the abstract model to the bottom.

QAbstractItemModel* model = your_tree_view->model();

QModelIndex index0 = model->index(0, 0);
QMap<int, QVariant> data = model->itemData(index0);
// check siblings of the item; should be restored later
model->removeRow(0);

int rowCount = model->rowCount();
model->insertRow(rowCount);
QModelIndex index1 = model->index(rowCount, 0);
model->setItemData(index1, data);

once item moved in the model your treeview widget should update itself accordingly

in case you need to change the size of the item shown by your treeview install an item delegate and override its sizeHint method

hope this helps, regards

Problem

Question says it all how do you raise and lower [change the positions of ] QTreeWidgetItems in a QtreeWidget ,

Original source