更改treeview gtk中列的字体颜色 [英] Changing font color on a column in treeview gtk
问题描述
我有一个treeview,我想改变一列的文本颜色。
我怎么能这样做?
谢谢 到目前为止Vala没有做太多的事情)
有几种方法可以实现这一点。您可以更改文本cellrenderer(GtkCellRendererText)的设置,例如:
$ p $ g $ object_set(your_text_cell_renderer,foreground,
red,foreground-set,TRUE);
另一种方法是使用标记:
> highlight_txt = g_strconcat(< span background ='yellow'foreground ='black'>,
my_text,< / span>,NULL);
g_object_set(your_text_cell_renderer,markup,highlighted_txt,NULL);
要在特定条件下单独更改每列的字体颜色,请输入
gtk_tree_view_insert_column_with_data_func或gtk_tree_view_column_set_cell_data_func
被使用,它们在GtkTreeView的在线文档中有描述。您可以为每列使用
不同的文本单元格渲染器来保持设置不同。
可以按照类似的方式完成:
for(columns_cnt = 0; columns_cnt< NUMBER_OF_COLUMNS; columns_cnt ++){
text_renderer = gtk_cell_renderer_text_new();
列[columns_cnt] = gtk_tree_view_column_new_with_attributes
(column_header_txt [columns_cnt],text_renderer,
text,columns_cnt,NULL);
gtk_tree_view_column_set_cell_data_func(columns [columns_cnt],text_renderer,
(GtkTreeCellDataFunc)
set_column_attributes,NULL,NULL);
static void set_column_attributes(GtkTreeViewColumn * cell_column,
GtkCellRenderer * txt_renderer,
GtkTreeModel * cell_model,
GtkTreeIter * cell_iter,
gpointer指针)
{
//使用g_object_set或其他的东西。
}
I've a treeview and I want to change the text color on one column.
How could I do this??
thanks
(Refering to the standard C methods, haven't done much with Vala so far)
There are several ways to achieve this. You can change the settings of the text cellrenderer (GtkCellRendererText), an example would be
g_object_set (your_text_cell_renderer, "foreground",
"red", "foreground-set", TRUE);
Another way is using markup:
highlighted_txt = g_strconcat ("<span background='yellow' foreground='black'>",
my_text, "</span>", NULL);
g_object_set (your_text_cell_renderer, "markup", highlighted_txt, NULL);
To change the font color of each column individually on certain conditions, gtk_tree_view_insert_column_with_data_func or gtk_tree_view_column_set_cell_data_func are used, they are described in the online documentation for GtkTreeView. You can use different text cell renderers for each column to keep settings separate.
It can be done in a way similar like this:
for (columns_cnt = 0; columns_cnt < NUMBER_OF_COLUMNS; columns_cnt++) {
text_renderer = gtk_cell_renderer_text_new ();
columns[columns_cnt] = gtk_tree_view_column_new_with_attributes
(column_header_txt[columns_cnt], text_renderer,
"text", columns_cnt, NULL);
gtk_tree_view_column_set_cell_data_func (columns[columns_cnt], text_renderer,
(GtkTreeCellDataFunc)
set_column_attributes, NULL, NULL);
}
...
static void set_column_attributes (GtkTreeViewColumn *cell_column,
GtkCellRenderer *txt_renderer,
GtkTreeModel *cell_model,
GtkTreeIter *cell_iter,
gpointer pointer)
{
// Use g_object_set or something else here.
}
这篇关于更改treeview gtk中列的字体颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!