How to colorize a Treeview? Solution!

Hi @all,

since i had the same problem as described in
Ruby/Tk: How to colorize a Treeview? - Ruby - Ruby-Forum and due to the fact that i don’t
found any
information how to realize this functionality i tried around a lot and
found a solution i want to share with you. Perhaps this is clear to
everyone, but for me it wasn’t… :wink:

Problem 1: It seems that the insert method only evaluates the first hash
value of the yielded options. So in my example below only the text will
be displayed in first column of the treeview. No tags will be added to
the item.

item = @sourceTreeView_TestCases.insert(‘’, ‘end’, {:text =>
testcase.name, :tags => testcase.result})

If you do the following you can use the tags later but the first column
of you treeview is empty:

item = @sourceTreeView_TestCases.insert(‘’, ‘end’, {:tags =>
testcase.result, :text => testcase.name})

But you can reach the goal in 2 steps:

item = @sourceTreeView_TestCases.insert(‘’, ‘end’, :text =>
testcase.name)
item.tags(testcase.result)

So if you want to change the background color now, you can use the tag
for that:

@sourceTreeView_TestCases.tag_configure(‘failed’, :background => ‘red’)
or
@sourceTreeView_TestCases.tag_configure(‘configure’, ‘failed’,
:background => ‘red’)

Problem 2: I tried to use tags with whitespaces. This doesn’t work!

I hope this helps someone…

Bye bye

K.

Ok… @home it worked for me, but in the company it doesn’t. :confused:

@home-config: ruby 1.9.3p545 (Ubuntu 12.04.5)
@company: ruby 1.8.7 (Cent OS, don’t know the version atm)

Bye

K.