GTK3 TextView文本颜色与字体 [英] Gtk3 textview text color vs font

查看:278
本文介绍了GTK3 TextView文本颜色与字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用gtk_css_provider_new创建CSS提供程序,并使用gtk_css_provider_load_from_data加载它时,将其提供给"textview {color:red; font:30px serif;}"作为数据,并通过使用gtk_style_context_add_provider将其应用于gtk_text_view,结果是它将字体大小更改为30,但将文本颜色保留为黑色.我该怎么做才能更改文本颜色?

When I create a CSS provider with gtk_css_provider_new, and load it with gtk_css_provider_load_from_data, giving it "textview { color: red; font: 30px serif; }" as the data, and apply it to a gtk_text_view by using gtk_style_context_add_provider, the result is that it changes the font size to 30, but leaves the text color as black. What do I have to do the change the text color?

它更改了字体大小,表明CSS确实在工作.它没有改变颜色表明它只是部分起作用.有什么特别的事情可以改变文本的颜色吗?与更改字体大小有什么不同吗?

That it changes the font size shows that the CSS is actually working. That it doesn't change the color shows that it's only partly working. Is there something special that has to be done to change text color? Something different than what changes the font size?

如果我使用gdk_rgba_to_string显示rgba,它将显示为"rgb(255,0,0)",这表明样式上下文实际上具有红色.因此,唯一的问题是,当使用30px衬线作为实际字体时,为什么红色不用作实际文本颜色.

If I use gdk_rgba_to_string to show the rgba, it shows it as "rgb(255,0,0)" which shows that the style context actually has the color red. So the only issue is why the red isn't used as the actual text color when the 30px serif is used as the actual font.

推荐答案

要更改文本的颜色,您必须在CSS中选择TextView的文本部分...类似

To change the color of the text you have to select the text part of the TextView in CSS... it would be something like this

textview text {
color : #4fc3f7;
}

这会将文本颜色更改为蓝色.如果要进行更多修改,可以始终使用Gtk检查器来标识与窗口关联的css节点(Ctrl + Shift + I或D).

This would change the text color to blue.You could always use the Gtk inspector to identify the css nodes associated with the window(Ctrl + Shift + I or D ) if you want to modify more..

另一种方法是使用(gtk_text_buffer_create_tag https://developer.gnome .org/gtk3/stable/GtkTextView.html ),然后使用(gtk_text_buffer_insert_with_tags_by_name)

Another way to do this is to use (gtk_text_buffer_create_tag https://developer.gnome.org/gtk3/stable/GtkTextView.html) and add the text using (gtk_text_buffer_insert_with_tags_by_name)

这篇关于GTK3 TextView文本颜色与字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆