Qt-interest Archive, July 2007
QTreeView/ItemModel: change decoration for expanded items?
Message 1 in thread
Hi,
how do i change the decoration pixmap for an expanded QTreeView item
(qt4.3)?
There is only a single Qt::DecorationRole the model can react on. No
Qt::ExpandedDecorationRole or information if an item is expanded or not.
An ItemDelegate only gets the pixmap to draw and no model index where i
could ask the view if the item isExpanded(index).
I don't want to pass the view to the model because this would bind the
model to a single view.
The Dir view example shows a dialog image with a different expanded
icon. But that seems to be a fake. If i a set a dir model into a tree
view it doesn't change the pixmap for an expanded icon.
Any idea?
Martin
--
[ signature omitted ]
Message 2 in thread
Martin Hauner schrieb:
> Hi,
>
> how do i change the decoration pixmap for an expanded QTreeView item
> (qt4.3)?
>
> There is only a single Qt::DecorationRole the model can react on. No
> Qt::ExpandedDecorationRole or information if an item is expanded or not.
QTreeView::isExpanded() wouldn't do?
Martin
--
[ signature omitted ]
Message 3 in thread
The model doesn't know anything about the view.
It is the views responsibility to track which items are expanded or collapsed, but the model framework does not seem to have a role for an expanded decoration.
There's only a single Qt::DecorationRole, and the model does not know if the item is expanded or collapsed.
It would be possible to pass the view to and store a pointer in the model, but this breaks the separation between view and model responsibilities, and it also breaks when there is more than one view to the same model.
One way to work around it may be to define a custom role for this purpose, and then subclass the view class(es) you need to selectively ask the model for the decoration role or your custom role depending on whether the item is expanded or not.
--
[ signature omitted ]
Message 4 in thread
Hi,
Erik Haugen Bakke wrote:
> The model doesn't know anything about the view.
>
> It is the views responsibility to track which items are expanded or
> collapsed, but the model framework does not seem to have a role for
> an expanded decoration. There's only a single Qt::DecorationRole, and
> the model does not know if the item is expanded or collapsed.
Yes, that's the issue.
> It would be possible to pass the view to and store a pointer in the
> model, but this breaks the separation between view and model
> responsibilities, and it also breaks when there is more than one view
> to the same model.
Yes again.
> One way to work around it may be to define a custom role for this
> purpose, and then subclass the view class(es) you need to selectively
> ask the model for the decoration role or your custom role depending
> on whether the item is expanded or not.
>
> -- Erik H. Bakke
In QTreeView I would have to overwrite drawRow but there is a lot of
code in this method. I don't think i want to implement that myself.
I could overwrite the paint method in QItemDelegate but there is also
enough code in this method that i don't want to overwrite it.
Another way would be to overwrite drawDecoration in QItemDelegate and
ignore the give pixmap. Unfortunately drawDecoration doesn't have an
QModelIndex parameter i could use to ask the model for an expandedn
decoration.
Looks like there is no simple and clean way to do this.
Disapointing... :(
--
[ signature omitted ]