Hi,
I use something like this:
@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?
on 2011-09-21 00:53
on 2011-09-21 09:50
Marc Heiler wrote in post #1023026: > 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 gender_text_renderer = Gtk.cellRendererText.new column.pack_start(gender_text_renderer, false) column.set_attributes(gender_text_renderer, :text => 6) You can have a look at the pygtk tutorial : http://www.pygtk.org/pygtk2tutorial/sec-CellRenderers.html mainly http://www.pygtk.org/pygtk2tutorial/examples/filelisting.py regards Simon
on 2011-09-21 10:14
On 20 September 2011 23:53, Marc Heiler <ruby-forum-incoming@andreas-s.net> wrote: > 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? Yes - https://gist.github.com/1231530 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). HTH, Geoff
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.