使用 gtk3,如何更改默认的 GtkWindow 标题栏颜色?它会涉及 GtkStyleContext 吗?我只使用了 GtkCssProvider。
问问题
2687 次
2 回答
2
您不能从 GTK 更改标题栏颜色。标题栏由窗口管理器绘制,GTK 对此一无所知。您只能通过“提示”与窗口管理器进行通信,例如窗口是否应该有标题栏或应该在那里显示什么字符串,但窗口管理器可以随意忽略它们。
于 2012-01-08T13:54:22.433 回答
2
你可以做到......(至少在 Linux 上)发生的情况是你的窗口没有被装饰,然后用标题栏“装饰”(恰好有一个血腥的“show_close_button”,所以我猜这是有意的利用 )
class base_ui(Gtk.Window):
def __init__(self):
# initializing self ( the window )
Gtk.Window.__init__(self, title="window title")
self.set_border_width(1)
self.set_default_size(800, 600)
# Create the header bar
hb = Gtk.HeaderBar()
# This is the id of the header bar to be used in the css file
hb.set_name("mw_hb")
# we can even set a close button ...
# you can add the other buttons as well, but have to do it yourself
hb.set_show_close_button(True)
# the effective text in the titlebar ( the window title )
# is props.title
hb.props.title = "win title"
# and here comes the sun - we set our headerbar as the new titlebar.
# Bazinga
self.set_titlebar(hb)
于 2018-11-29T08:48:01.487 回答