GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Mon Jul 28, 2014 4:26 pm

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: problem using text markup + background color for treeview
PostPosted: Sun Nov 18, 2012 9:44 pm 
Offline
Familiar Face

Joined: Mon Jul 11, 2011 10:24 am
Posts: 15
Hi,

I encountered a problem when using g_object_set ("background") together with text markup that sets fore- and background color of text inside a tree view cell. If I do this, if the highlighted text starts at the beginning of the cell or spans the whole cell, the foreground color is ignored.
I'll give you a code example and a screenshot to clarify this:
First I set the background color for the whole cell:

Code:
g_object_set (txt_renderer, "background", "#364074", "background-set", TRUE);


So far everything is alright, now I want to highlight some part of the cell, since this is part of a search functionality:

Code:
highlighted_txt = g_strconcat ("<span background=\"yellow\" foreground=\"black\">", match, "</span>", NULL));
g_object_set (txt_renderer, "markup", highlighted_txt, NULL);


But if the highlighted text is identical to the whole text of the cell or it starts at the beginning of it, the foreground color setting is ignored. I have included a screenshot to show this effect.

Actually the whole real code behind creating the markup is done by a modified version of the example code listed at the glib docu page for g_regex_replace_eval, but the generated markup text should be correct, it is for example:

Code:
<span background="yellow" foreground="black">no</span> content


Am I missing here something regarding usage of <span>?

Thanks

Marcus


Attachments:
markup_error.png
markup_error.png [ 52.52 KiB | Viewed 1036 times ]
Top
 Profile  
 
 Post subject: Re: problem using text markup + background color for treevie
PostPosted: Mon Nov 19, 2012 12:18 am 
Offline
Never Seen the Sunlight

Joined: Thu Mar 24, 2011 2:10 pm
Posts: 328
Location: Sydney, Australia
You can probably scrub the whole cell criterion as this is superfluous and covered by the beginning of cell case. I really don't know why there would be a conflict. Is this the case only when you do a g_object_set background?
It's generally much better to make style settings through an rc file (gtk2) or through css (gtk3).
Instead of the background property, you might want to try to use the cell-background property of the GtkCellRenderer parent.

btw shouldn't
Code:
g_object_set (txt_renderer, "background", "#364074", "background-set", TRUE);
end in a NULL or was this just a typo?


Top
 Profile  
 
 Post subject: Re: problem using text markup + background color for treevie
PostPosted: Mon Nov 19, 2012 12:38 am 
Offline
Familiar Face

Joined: Mon Jul 11, 2011 10:24 am
Posts: 15
Paul Childs wrote:
shouldn't
Code:
g_object_set (txt_renderer, "background", "#364074", "background-set", TRUE);
end in a NULL or was this just a typo?


Yes, the renderer settings are in fact larger, I just forgot to add the NULL for the excerpt.

Paul Childs wrote:
Instead of the background property, you might want to try to use the cell-background property of the GtkCellRenderer parent.


I've tried that a few moments before your posting, but it doesn't change anything.

Paul Childs wrote:
Is this the case only when you do a g_object_set background?


Good point, I've seen now that this effect is background-color-independent. I just didn't have a foreground setting for a cell without a background-color-setting since it was not necessary, but I've tried it now.

I'll use your suggestions for further investigations and post here if I solved the problem. Thanks for your answer!

Marcus


Top
 Profile  
 
 Post subject: Re: problem using text markup + background color for treevie
PostPosted: Mon Nov 19, 2012 6:53 pm 
Offline
Familiar Face

Joined: Mon Jul 11, 2011 10:24 am
Posts: 15
Well I did some kind of workaround for now.

First I check if the cell will have a background color (dependent on some conditions).
If this will be the case, I put <span foreground="'white'> and <span> around the text, so in the end it looks for example like this:
<span foreground='white'><span background='yellow' foreground='black'>no</span> content</span>

Now when it comes to cell rendering, g_object_set will only set a foreground color (to white) if it is a cell with a background color and there is no highlighted text for the cell. This avoids a possible conflict of a foreground color set by the cell renderer and by the <span foreground> markup.

I wanted to avoid external css files or so for setting just one one color markup that is only used for the search functionality.

If there is a better fix I am of course still interested in it.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group