ruby-****@sourc*****
ruby-****@sourc*****
2012年 8月 14日 (火) 02:40:29 JST
------------------------- REMOTE_ADDR = 184.145.90.35 REMOTE_HOST = URL = http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-treeview-renderer-attributes ------------------------- @@ -10,7 +10,13 @@ col.add_attribute(renderer, "text", 0) -This means that the text cell renderer property "text" will be set to the string in model column 0 of each row to be drawn. It is important to realize that Gtk::TreeView#add_attribute will set the property to whatever is specificed in the model column ((*at the time of rendering*)). +This means that the text cell renderer property "text" will be set to the string in model column 0 of each row to be drawn. It is important to realize that Gtk::TreeView#add_attribute will set the property to whatever is specified in the model column ((*at the time of rendering.*)) + +Do not be misled by the following code and also the Gtk API documentation that explains it: + + column = Gtk::TreeViewColumn.new("Buy", renderer, {:text => 3, :foreground => 3}) + +Particularly misleading in the above code and in the API documentation is the part (if read inattentively) suggesting that the hash of attributes may be used to set the attributes to their respective values. That may have been an original Gtk GUI developer's goal but it never materialized. One may incorrectly think that in the above code we could set the foreground colour directly when creating the view column. This, however, is not the case, namely all attributes in the hash can only be assigned their respective column numbers in the tree view, which with the exception of :text attribute, is a rather ridiculous thing in most everyday situations. There are two more noteworthy things about Gtk::CellRenderer properties: one is that sometimes there are different properties which do the same, but take different arguments, such as the "foreground" and "foreground-gdk" properties of Gtk::CellRendererText (which specify the text colour). The "foreground" property take a colour in string form, such as "Orange" or "CornflowerBlue", whereas "foreground-gdk" takes a Gdk::Color argument. It is up to you to decide which one to use - the effect will be the same. The other thing worth mentioning is that most properties have a "foo-set" property taking a boolean value as argument, such as "foreground-set". This is useful when you want to have a certain setting have an effect or not. If you set the "foreground" property, but set "foreground-set" to FALSE, then your foreground color setting will be disregarded. This is useful in cell data functions, or, for example, if you want set the foreground colour to a certain value at start-up, but only want this to be in effect in some columns, but not in others (in which case you could just connect the "foreground-set" property to a model column).