[Qt-interest] QTreeView, additional images

Thomas Ehrnhoefer thomas.ehrnhoefer at tasktop.com
Tue Apr 26 16:32:12 CEST 2011


Thanks Andre, Eckhard,

I will see what I can find out about the things you mentioned.
Sadly caching each of the images in composite form is less than ideal, as
the combinations are plenty, and at least one of the images is retrieved
from the network.

On Tue, Apr 26, 2011 at 2:15 AM, Eckhard Jokisch
<e.jokisch at orange-moon.de>wrote:

> On Tuesday 26 April 2011 01:27:54 Thomas Ehrnhoefer wrote:
> > Hi
> >
> > I have a TreeViewer, and I would like to have additional images
> available.
> > I don't want multiple columns, just additional decorations (images) to
> > (some) of the items (e.g. a "changed" indicator). An example would be
> > http://oboedit.org/docs/images/tree_view_single.png
> >
> > Since I am new to Qt, I am wondering what the best way (if there is any)
> to
> > do this would be. Most likely some custom drawing I assume, but I am
> unsure
> > on how/where to start.
> >
> > Any hints are very welcome
> >
> > Thanks
> > Thomas
>
> I think what you are looking for is something like the below implemented
> into
> your ::data() function of the model where "item" is an item out of the
> model
> and the item->status() returns either CHANGED or UNCHANGED or somethins
> else
> useful.
> The switch over the actual index.column() allows you to have different
> icons in
> different collumns - which you don't need right now but you never know
> what's
> coming next ;)
>
> Cheers
> Eckhard
> .....
> QVariant YourModel::::data(const QModelIndex &index, int role) const
>  {
>     if (!index.isValid())
>         return QVariant();
>
>        if (role == Qt::DecorationRole )
>       {
>         QPixmap p;
>
>         switch(index.column())
>         {
>         case 0:
>             switch(item->status() )
>             {
>             case CHANGED:
>                 p.load(":/icons/changed-icon.png");
>                 break;
>             case UNCHANGED:
>                 p.load(":/icons/unchanged-icon.png");
>                 break;
>             default:
>                 p.load(":/icons/some-icon.png");
>                 break;
>             }
>             break;
>         case 1:
>             if(p.isNull())
>             {
>                 p.load(":/icons/warn.png");
>             }
>             else
>             {
>                 p.load(":/icons/ok.png");
>             }
>             break;
>         default:
>             break;
>         }
>         return p;
>       }
> .....
> }
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
>



-- 
Thomas Ehrnhoefer
Software Developer, http://tasktop.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110426/94b8c6e5/attachment.html 


More information about the Qt-interest-old mailing list