After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 322387 - setting the background color of an entire row in a GtkTreeView
setting the background color of an entire row in a GtkTreeView
Status: RESOLVED OBSOLETE
Product: gtk+
Classification: Platform
Component: Widget: GtkTreeView
unspecified
Other All
: Normal enhancement
: Small API
Assigned To: gtktreeview-bugs
gtktreeview-bugs
Depends on:
Blocks:
 
 
Reported: 2005-11-25 02:20 UTC by Tim Evans
Modified: 2018-02-10 03:21 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Patch against gtk+-2.6.10 to add the new feature (9.52 KB, patch)
2005-11-25 02:22 UTC, Tim Evans
none Details | Review
Revised patch against gtk+-2.10.9 (5.99 KB, patch)
2007-01-31 03:16 UTC, Tim Evans
none Details | Review

Description Tim Evans 2005-11-25 02:20:08 UTC
To enchance one of my products, I was wanting to set the background colour of
rows in a treeview.  The end result is something similar to the rules-hint but
with the shade for each row defined programtically.  Setting the
GtkCellRenderer::cell-background property doesn't work for this because it
doesn't cover the entire row.  There are white spaces left around cells, and
invisible cells are completely white.

As an alternative, I've added a new function
"gtk_tree_view_set_row_background_func" (similar to
gtk_tree_view_set_row_separator_func) that lets programmers provide a callback
function to customise the row background colours.  I'll attach the patch for
this function.

Does anyone else think this a good idea and something that could be added to
GTK, either in the current form or with modifications?
Comment 1 Tim Evans 2005-11-25 02:22:03 UTC
Created attachment 55208 [details] [review]
Patch against gtk+-2.6.10 to add the new feature

Sorry about this being against an old version.
Comment 2 Kristian Rietveld 2006-05-03 14:00:33 UTC
I am going to try to get this in 2.10, because it is nice/useful for implementing grouping.  I am still contemplating about the API though.

I thinking of:
  * renaming the function to just "GtkTreeViewRowBackgroundFunc",
  * drawing the background differently.  Right now, when a custom background color is set that color is used without question, all other attributes are ignored.  The only attribute passed to the background function is the "Selected" attribute.  I see two options, we could pass more attributes to the function (also "detail" for example, though then the function will have to handle the "row-ending-details" style property ...).  Another option might be to request a color from the function (while just passing the treeview and an iter/path), modify the style and pass that to gtk_paint_flat_box() so the theme engine will have a chance of customizing it (it'll take the state, detail (and row-ending-details) into account).  But that might not be wished of course ...

I'll update the patch once I've made up my mind on what to do.
Comment 3 Tim Evans 2006-05-04 02:06:12 UTC
Thank you for taking an interest in this.

The way I ended up using this in our application was just colour alternating groups of rows in the same shades as odd/even rows.  Discovering what the even/odd row colours are turns out to be non-trivial because the style properties default to unset rather than to the default colours.  I ended up having to copy the colour manipulation logic out of the depths of the treeview rendering code; something I would prefer to avoid.  If this case is common, it would be nice to make it easy to implement while still supporting the more complex case via a more complex api.

From the application programmers point of view I think the ideal method would be to provide (via a callback or a model column) a "group-id" atom for each row.  Adjacent rows with the same group-id become a group, and alternating groups would be drawn with alternating "even" and "odd" background colours in the same way as the current rules-hint rendering.  I'm not sure how you would quickly determine the odd-group/even-group state for a row, especially in a tree as nodes get expanded and collapsed.

The simplest to implement would be a callback or model column that redefines the odd/even state of each row.  This forces the application programmer to keep track of this information as rows are added and removed, and wouldn't work well with trees except in the simplest cases.
Comment 4 Kristian Rietveld 2006-06-12 14:10:47 UTC
Sounds like you are describing #318163 (see the bottom for the rules-interval property).

For the effect I was trying to achieve this is maybe better solved as a duplicate of #309474.
Comment 5 Tim Evans 2006-06-12 22:33:02 UTC

*** This bug has been marked as a duplicate of 309474 ***
Comment 6 Tim Evans 2006-06-12 22:35:08 UTC
Oops, I didn't actually mean to submit that, sorry for the spam.
Comment 7 Tim Evans 2006-06-13 02:15:49 UTC
Having actually read both those bugs, rather than confusing myself my clicking the wrong button, I don't think either of them addresses my problem.  The concept of categories is similar to bug #309474, and the idea of alternating the colour on groups of rows is similar to the rules-interval in bug #318163, but neither is exactly right.
Comment 8 Tim Evans 2007-01-31 03:16:30 UTC
Created attachment 81565 [details] [review]
Revised patch against gtk+-2.10.9

This new patch:
- Changes the names to GtkTreeViewBackgoundFunc and gtk_tree_view_set_background_func.
- Passes the tree view rather than the model as the first argument to the row background func, so attributes like selection and default colours can be found easier.
- Doesn't pass 'selected' to the row background func.

The rendering method is unchanged as I haven't spent the time to work out a better way to do it.
Comment 9 Matthias Clasen 2018-02-10 03:21:25 UTC
We're moving to gitlab! As part of this move, we are closing bugs that haven't seen activity in more than 5 years. If this issue is still imporant to you and
still relevant with GTK+ 3.22 or master, please consider creating a gitlab issue
for it.