@list_store_party = Gtk::ListStore.new(
Gdk::Pixbuf,
String, # ID
String, # Name
String, # Profession
String, # Number of Attacks.
String, # Race
String, # Gender
String, # Level
String, # Hitpoints
Gdk::Pixbuf,
Float # Lifebar
)
Now I would like to display both a String and an Image (Gdk::Pixbuf) in
a ListStore field (displayed via a TreeView).
But is this possible?
More specifically, in this display of a “fantasy hero group”, I would
like to display the gender (“male” or “female”) but also show a little
gender icon right next to this text. But, I don’t want to use a new
field.
So my question is, can I combine both String and Gdk::Pixbuf in one
field?
More specifically, in this display of a “fantasy hero group”, I would
like to display the gender (“male” or “female”) but also show a little
gender icon right next to this text. But, I don’t want to use a new
field.
So my question is, can I combine both String and Gdk::Pixbuf in one
field?
Most of the work is done by the Gtk::TreeViewColumn, which can contain
multiple Gtk::CellRenderers.
Gtk::TreeViewColumn#pack_start(renderer, expand) &
Gtk:TreeViewColumn#set_attributes(renderer, attributes) then allow you
to configure what data it displays from the model (ie. the
Gtk::ListStore).
Now I would like to display both a String and an Image (Gdk::Pixbuf) in
a ListStore field (displayed via a TreeView).
But is this possible?
It sure is.
More specifically, in this display of a “fantasy hero group”, I would
like to display the gender (“male” or “female”) but also show a little
gender icon right next to this text. But, I don’t want to use a new
field.
So my question is, can I combine both String and Gdk::Pixbuf in one
field?
The ‘store’ cannot do that, of course, but a treeview column can have
multiple cellrenderers. You have to think at a single cell like an hbox
of cellrenderers.
For example (untested):
column = Gtk::TreeViewColumn.new(“Gender”)
pixbuf_renderer = Gtk.cellRendererPixbuf.new
column.pack_start(pixbuf_renderer, false)
column.set_cell_data_func(pixbuf_renderer) do |column, cell, model,
iter|
if iter[6] ~= /$m/i then
cell.pixbuff = <male_pixbuff>
elsif iter[6] ~= /$f/i then
cell.pixbuff = <female_pixbuff>
else
cell.pixbuff = <unknown_pixbuff>
end
end