CellRenderText properties question.



The Gnome 2.0 porting docs contain the following information on the
GtkCellRender widget (under new widgets in the docs):

    * Cell renderer properties can be set per-renderer or per-cell (based on
data in the model). So for example, the text renderer has a "foreground"
property for the foreground color. You could set the foreground color globally
for an entire column, or you could have the foreground property change per-cell
according to data in the model.

    * For a given cell renderer, multiple fields in the model can affect it.
For example, if your mail client model has a boolean field indicating "unread
message," and a string field indicating "subject," you can set the "bold"
property of the cell from the unread flag and the "text" property of the cell
from the subject.


Looking at the API docs for GtkCellRender and GtkCellRenderText, I see
the following description under gtk_cell_renderer_text_new ():

...Also, with GtkTreeViewColumn, you can bind a property to a value in a
GtkTreeModel. For example, you can bind the "text" property on the cell
renderer to a string value in the model, thus rendering a different string in
each row of the GtkTreeView.

However, I can't really find any code examples of how to do anything
suggested in these docs. For example, I have a GtkTextView that only has
a single column in it. When I click a button in my window, I want to
find out the current selection in that TreeView and set it's text to Red
or Bold or something. I can't seem to find anything that shows how to
get the exact cell and then change its attributes. I can do it globably
for a column (and have for testing) but not on a single cell. 

These docs seem to imply that I need some further data in my cell model
to apply an attribute to. So, it seems like I have to have an extra
invisible column in my model that holds text attributes, update the
column text with a new string (say to "red" from "black" in order for
the text in the visible column to have the attribute change. This seems
very confusing to me. The docs say "based on data in the model" but it's
not clear what that means, if it's actual attributes stored in the
model, or just change based on a programmatic condition (col 1 is true
so set text to bold).

How can I change attributes on a single cell without having extra data
in my model or do I really need the extra data in my model? I'm sure I'm
missing something obvious but the docs are confusing. Also, storing
extra attribute data in my ListStore adds memory overhead.

Additionally, I see this description for
gtk_tree_view_column_cell_set_cell_data:

Sets the cell renderer based on the tree_model and iter. That is, for every
attribute mapping in tree_column, it will get a value from the set column on
the iter, and use that value to set the attribute on the cell renderer.

I'm sorry but that's not very clear, and in fact it's extremely
confusing. Maybe RedHat could hire me as a technical writer (I have
several years experience at this and worked for Metrowerks as a
professional technical writer).

Any help is greatly appreciated.

-- 
 .''`.      Carl B. Constantine
: :' :     duckwing duckwing ca
`. `'    GnuPG: 135F FC30 7A02 B0EB 61DB  34E3 3AF1 DC6C 9F7A 3FF8
  `-  Debian GNU/Linux -- The power of freedom

Attachment: pgp5YRFzCFCM1.pgp
Description: PGP signature



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]