Re: An image on a TreeView cell
- From: "Jonathon Jongsma" <jonathon quotidian org>
- To: "Iker Perez de Albeniz" <ialbeniz cbt es>
- Cc: gtkmm-list gnome org
- Subject: Re: An image on a TreeView cell
- Date: Wed, 26 Sep 2007 09:31:11 -0500
On 9/26/07, Iker Perez de Albeniz <ialbeniz cbt es> wrote:
> I have copied from the gtkmm documentation an example of a treeview
> table with a progress-bar.. i haver tried top modify the code to change
> the progress bar to a image.. like this:
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> row[m_Columns.m_col_image] = "./skin/cerrar.png"; //set the path to the
> image
> row[m_Columns.m_col_foo] = false;
> row[m_Columns.m_col_name] = "Scan3";
> row[m_Columns.m_col_number] = 1232;
>
> //Add the TreeView's view columns:
> //We use the *_editable convenience methods for most of these,
> //because the default functionality is enough:
>
> //Display a image bar instead of a text:
> Gtk::Image* cell = new Gtk::Image;
> int cols_count = m_TreeView.append_column("Tipo", *cell);
> Gtk::TreeViewColumn* pColumn = m_TreeView.get_column(cols_count - 1);
> if(pColumn)
> {
> #ifdef GLIBMM_PROPERTIES_ENABLED
> pColumn->add_attribute(cell->set(), m_Columns.m_col_image);
> #else
> pColumn->add_attribute(*cell, "value", m_Columns.m_col_image);
> #endif
> }
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
> the biulder crashes in two pints:
>
> int cols_count = m_TreeView.append_column("Tipo", *cell); <-- imposible
> to appned an image
>
> pColumn->add_attribute(cell->set(), m_Columns.m_col_image); <--
> Gtk::Image::set() function not found...
>
> any idea abaut how to add an image to an a treview cell...??
the append_column() function needs to take either a CellRenderer or a
TreeModelColumn. You can't just pass it a Gtk::Image. Make sure you
read the API documentation:
http://www.gtkmm.org/docs/gtkmm-2.4/docs/reference/html/classGtk_1_1TreeView.html
What you probably need to do is define your column m_col_image as type
Glib::RefPtr<Gdk::Pixbuf> instead of a string specifying the filename.
Then your code above would need to be changed to something like
(NOTE: THIS IS NOT TESTED):
row[m_Columns.m_col_image] = Gdk::Pixbuf::create_from_file("./skin/cerrar.png");
int cols_count = m_TreeView.append_column("Tipo", m_Columns.m_col_image);
That should be all you need. gtkmm is smart enough to notice that
your column is of type Gdk::Pixbuf so it creates a CellRendererPixbuf
for it so that an image is displayed in the treeview.
Hope that helps
--
jonner
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]