PDA

View Full Version : qtableview hide/disable icon (Qt::DecorationRole)



Talei
12th November 2011, 13:49
Hello,
I have a model (QStandardItemModel) that is used by 2 views. One of them is QTableView.
In my model I have data with Qt::DecorationRole for icon's that are displayed in other view.

The question: how to disable icons on QTableView (without delegates/subclass - I want to go simplistic here).

Currently I did resolve this using setIconSize( QSize(0,0) ) but I don't know if view (QTableView) still query model for Qt::DecorationRole.

My question also could be: is view, when is set setIconSize( QSize(0,0) ) to 0, query model for that item data roles?

Best regards.

grin
12th November 2011, 21:18
For disabling - Try to set disable flags (item->flags() & ~Qt::ItemIsEnabled) for needed item in your model through void QStandardItem::setFlags()
For hidding icon - try to set empty icon ( QIcon()) for needed item through QStandardItem::setIcon().

Talei
13th November 2011, 04:24
Yes, but there is a problem with that, because this model is used by 2 views, ListView (that display icons) and TableView (that don't display icons).
So I can't modify model itself.

And I don't want to disable item, I want to force QTabelView to ignore item data with Qt::DecorationRole (icons).

Lykurg
13th November 2011, 09:35
You can use a proxymodel which filters the decoration role. Then set the original model as source. Thus you can use only one model with different viewing parameters.

Talei
13th November 2011, 15:15
I thought about that but currently it's just initial implementation so I want to go minimalistic with this.

And for educational reason:
is view, when is set setIconSize( QSize(0,0) ) to 0, query model for that item data roles?

Lykurg
13th November 2011, 20:49
As far as I can see yes: http://qt.gitorious.org/qt/qt/blobs/85f42777111060037476895ed08ded513d44a048/src/gui/itemviews/qstyleditemdelegate.cpp#line340
It is called regardless the size is 0 or not.