[Qt-interest] Fwd: Fwd: Fwd: decoration role for the tree model subclass

ami guru dosto.walla at gmail.com
Thu Dec 18 03:30:15 CET 2008


Thanks everyone !

It helped me and it works fine


Sajjad

---------- Forwarded message ----------
From: Scott Aron Bloom <scott at sabgroup.com>
Date: Wed, Dec 17, 2008 at 5:08 PM
Subject: Re: [Qt-interest] Fwd: Fwd: decoration role for the tree model
subclass
To: dosto.walla at gmail.com
Cc: qt-interest at trolltech.com


most of the calls into the model come from views and delegates.

Put a break point in your data method, eventually it will get called with a
request for the decoration role
-Scott
--Sent from my mobile device--
-----Original Message-----
From: "ami guru" <dosto.walla at gmail.com>
Date: Wednesday, Dec 17, 2008 5:09 am
Subject: [Qt-interest] Fwd: Fwd: decoration role for the tree model subclass
To: qt-interest at trolltech.com

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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20081218/86dc7b65/attachment.html 


More information about the Qt-interest-old mailing list