Python: 改变 GtkTreeview 中的 select 颜色
Python: Changing the select colour in a GtkTreeview
我想在树视图中禁用选择颜色。所以我想用 modify_base. I found this 解决方案将所选颜色设置为白色,但它不起作用。这是我的代码:
import gi
from gi.repository import Gdk, Gtk
gi.require_version('Gtk', '3.0')
treestore = InterfaceTreeStore()
treeview = Gtk.TreeView()
treeview.set_model(treestore)
treeview.modify_base(Gtk.StateFlags.SELECTED, Gdk.Color(red=65535, blue=65535, green=65535))
gtk_widget_modify_base
has been deprecated since 3.0. You could have used gtk_widget_override_background_color
, if it wasn't deprecated since 3.16. It's documentation 表示:
If you wish to change the way a widget renders its background you should use a custom CSS style
但是,如果您想禁用选择颜色,最简单的方法是取消选择。
您的 "changed"
信号回调可能如下所示:
def changed_cb(selection):
model, iter = get_selected (selection)
# if there is no selection, iter is None
if iter is None:
return
# do something useful
# now unselect
path = model.get_path(iter)
selection.unselect_path(path)
path.free() # not sure if python frees it automatically
我想在树视图中禁用选择颜色。所以我想用 modify_base. I found this 解决方案将所选颜色设置为白色,但它不起作用。这是我的代码:
import gi
from gi.repository import Gdk, Gtk
gi.require_version('Gtk', '3.0')
treestore = InterfaceTreeStore()
treeview = Gtk.TreeView()
treeview.set_model(treestore)
treeview.modify_base(Gtk.StateFlags.SELECTED, Gdk.Color(red=65535, blue=65535, green=65535))
gtk_widget_modify_base
has been deprecated since 3.0. You could have used gtk_widget_override_background_color
, if it wasn't deprecated since 3.16. It's documentation 表示:
If you wish to change the way a widget renders its background you should use a custom CSS style
但是,如果您想禁用选择颜色,最简单的方法是取消选择。
您的 "changed"
信号回调可能如下所示:
def changed_cb(selection):
model, iter = get_selected (selection)
# if there is no selection, iter is None
if iter is None:
return
# do something useful
# now unselect
path = model.get_path(iter)
selection.unselect_path(path)
path.free() # not sure if python frees it automatically