views:

284

answers:

1

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

+2  A: 

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

serge_gubenko
LOL, 1. get the model of the treeview.2. get the model index of the row / column .3. use the index to get the data .4. remove it.5. insert a blank row .6. get the index of the blank row.7. set the data of the blank row using the index.Back on Gtk+ the api on a treestore was like insert(), move_after(),move_before(),swap(), etc. This qt stuff is completley unintuitive, why people say its better than Gtk+ i'll never know. Once again thanks Serge.
spearfire
@spearfire: part of this is using the widget variants of the model/view setup in Qt. If you were doing a model yourself, you would just change where the data is in the model (and emit the appropriate signals), and the UI would update itself to match.
Caleb Huitt - cjhuitt
Your right, simply swapping data and children is far more effective
spearfire