简体   繁体   English

如何更改 GtkTextView 的背景颜色?

[英]How to change background color of GtkTextView?

How to change background color of GtkTextView?如何更改 GtkTextView 的背景颜色? I tried with normal widget set bg functionality but gtk is just changing border color of GtkText View.我尝试使用普通小部件集 bg 功能,但 gtk 只是更改 GtkText 视图的边框颜色。

Plus can some some please explain me with simple example, that how to change Text Color/Font/Text Size in GtkTextView (Whole text in GtkTextView)?另外,有些人可以用简单的例子来解释我,如何在 GtkTextView(GtkTextView 中的整个文本)中更改文本颜色/字体/文本大小?

I fond some examples but they are not working..我喜欢一些例子,但它们不起作用..

Thnaks, PP.纳克斯,PP。

gtk_widget_override_background_color()

This the GTK 3.x+ way (until GTK 3.16).这是 GTK 3.x+ 的方式(直到 GTK 3.16)。 From

https://developer.gnome.org/gtk3/unstable/GtkWidget.html#gtk-widget-modify-base https://developer.gnome.org/gtk3/unstable/GtkWidget.html#gtk-widget-modify-base

" gtk_widget_modify_base has been deprecated since version 3.0 and should not be used in newly-written code. Use gtk_widget_override_background_color() instead" " gtk_widget_modify_base自 3.0 版起已被弃用,不应在新编写的代码中使用。改用gtk_widget_override_background_color() "

UPDATE: thegtknerd notes that this method too is now deprecated and it has been since 3.16.更新:thegtknerd 指出,此方法现在也已弃用,并且从 3.16 开始。

As of gtk3, I believe the proper way to do that is through CSS.从 gtk3 开始,我相信正确的方法是通过 CSS。 Register a gtk style sheet though GtkCssProvider , then you can write this CSS: 通过 GtkCssProvider注册一个 gtk 样式表,然后你可以写这个 CSS:

textview text {
  background-color: @theme_bg_color;
}

We can see the relevant CSS nodes in the documentation for GtkTextView.我们可以在 GtkTextView 的文档中看到相关的 CSS 节点。 In this case I put @theme_bg_color which is an adwaita CSS variable , but you can as well put anything that goes in a usual CSS file, like red or #ff0000 .在这种情况下,我放置了@theme_bg_color ,它是一个 adwaita CSS 变量,但您也可以将任何内容放入通常的 CSS 文件中,例如red#ff0000

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM