Project

General

Profile

Refreshing WTreeView

Added by Dennis Schenzow about 6 years ago

Hello,

I have a problem refreshing a WTreeView with a custom WAbstractItemModel (like in Wt Widget Gallery https://webtoolkit.eu/widgets/trees-tables/mvc-item-models).

When the model changes (number of elements or just parameter) i refresh it with this code and it works.

layoutAboutToBeChanged().emit(); // Invalidates model indexes
...
layoutChanged().emit();

My problem is that after the refresh the treeview collapses.

Is there a way to prevent it?

Thanks


Replies (1)

RE: Refreshing WTreeView - Added by Roel Standaert about 6 years ago

Hello,

Layout changes invalidate the model indices. WTreeView does keep track of the expanded items by first converting their model indices into raw indices. However, in order to support this, you need to add a proper implementation of WAbstractItemModel::toRawIndex() and WAbstractItemModel::fromRawIndex() to your custom model.

You can also use more fine-grained signals like rowsAboutToBeInserted()/rowsInserted(). In that case, the model can appropriately shift the indices.

Note: the raw index does not actually need to be a valid pointer, you just need to make sure that model->fromRawIndex(model->toRawIndex(index)) == index.

Regards,

Roel

    (1-1/1)