[Qt-interest] Fwd: Fwd: decoration role for the tree model subclass
ami guru
dosto.walla at gmail.com
Wed Dec 17 14:08:10 CET 2008
Hello Sebastian,
I did according to your hint.
But the icon is not showing up along with the item name.
I think the reason is that data() function is called with display role by
default.
How to call that with the decoration role?
I would to understand the function call hierarchy in the model that i have
created
The manual says that for creating a tree model we have to subclass the
QAbstractItemModel and must
reimplement some of the functions. I would like to see how these over-ridden
functions are called.
Only then i would probably be able to track and call the data() with the
decoration role.
What do you think?
Regards
Sajjad
---------- Forwarded message ----------
From: Sebastian Fischer <creat at gmx.net>
Date: Wed, Dec 17, 2008 at 6:37 AM
Subject: Re: [Qt-interest] Fwd: decoration role for the tree model subclass
To: ami guru <dosto.walla at gmail.com>
Hi,
below is your data() function adapted to correctly handle the decoration
role.
This funtion serves as the source of all information about the item
referenced to by the given index. You already handle the Qt::DisplayRole and
just have to expand it for the Qt::DecorationRole, since the type of data
requested from the view is defined in the role variable, like so:
<<< BEGIN CODE >>>
QVariant H3DTreeModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
H3DTreeItem *item =
static_cast<H3DTreeItem*>(index.internalPointer());
if (role == Qt::DisplayRole)
return item->data(index.column());
else if (role == Qt::DecorationRole)
return item->icon();
else
return QVariant();
}
<<< END CODE >>>
Obviously H3DTreeItem need a (new) member function returning a QIcon (or
just can get the icon from somewhere else).
You might want to read through this, the 'Item Roles' section in particular:
http://doc.trolltech.com/4.4/model-view-model.html
Bye,
Sebastian Fischer
on 17.12.2008 at 01:19 you wrote:
hello ,
do i have to overload the data() function for Qt::DecorationRole ?
The link you provided did not make much sense to me
Could you please provide more reference to that?
Regards
Sajjad
---------- Forwarded message ----------
From: Benjamin <ikipou at gmail.com>
Date: Wed, Dec 17, 2008 at 12:18 AM
Subject: Re: [Qt-interest] decoration role for the tree model subclass
To: Qt Interest List <qt-interest at trolltech.com>
2008/12/16 ami guru <dosto.walla at gmail.com>
How to generate the icon in the above code and assign role for that
Hi,
The documentation says that the role for icons is Qt::DecorationRole:
http://doc.trolltech.com/4.4/qt.html#ItemDataRole-enum
best regards,
Benjamin
_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com <qt-interest at trolltech.com>
http://lists.trolltech.com/mailman/listinfo/qt-interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20081217/37c39f38/attachment.html
More information about the Qt-interest-old
mailing list