ruby-****@sourc*****
ruby-****@sourc*****
2012年 9月 20日 (木) 06:21:16 JST
------------------------- REMOTE_ADDR = 184.145.80.187 REMOTE_HOST = URL = http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-gtk2-treev-parts ------------------------- @@ -269,19 +269,19 @@ Columns are directly associated with cell renderer as well as with tree view. These relationships can be seen in the following code segment: - column = Gtk::TreeViewColumn.new("Buy", renderer, :text => BUY_IT) + column = Gtk::TreeViewColumn.new("Buy", renderer, {:text => BUY_IT}) treeview.append_column(column) +Note that curly braces are not needed in the above constructor, I just want to underscore, that we have a hash here. The following is a more verbose equivalent of the above: -or more verbose equivalent: - renderer = Gtk::CellRendererText.new column = Gtk::TreeViewColumn.new column.title = "Buy" column.pack_start(renderer, false) #column.add_attribute(renderer, :text, BUY_IT) - column.set_attributes(renderer, :text => BUY_IT) + column.set_attributes(renderer, {:text => BUY_IT}) # curly brackets indicate that this is a hash treeview.append_column(column) + Note, that in the second code segment you could use either of Gtk::TreeViewColumn#set_attributes or Gtk::TreeViewColumn#add_attribute instance methods to associate a the cell renderer with model column number. I should warn you that there are times when you will need to use the longer more verbose way of creating tree view columns. We will talk about this after we learn the basics (if you wish you can peek ahead to the next page into the section called "((<Multi-item Super Columns|tut-gtk2-treev-trees#Multi-item Super Columns>))".)