gtk3 GtkWindow标题栏颜色

发布于 2024-12-25 08:50:43 字数 77 浏览 2 评论 0原文

使用gtk3,如何更改默认的GtkWindow标题栏颜色?会涉及GtkStyleContext吗?我只使用过 GtkCssProvider。

Using gtk3, how can I change the default GtkWindow titlebar color? Would it involve GtkStyleContext? I've only used GtkCssProvider.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

聽兲甴掵 2025-01-01 08:50:43

您无法从 GTK 更改标题栏颜色。标题栏是由窗口管理器绘制的,GTK 对它一无所知。您只能通过“提示”与窗口管理器进行通信,例如窗口是否应该有标题栏或者应该在其中显示什么字符串,但窗口管理器可以随意忽略它们。

You can't change the titlebar color from GTK. The titlebar is drawn by the window manager, and GTK doesn't "know" anything about it. You can only communicate with the window manager through "hints", such as whether the window should have a titlebar or what string should be displayed there, but the window manager is free to ignore them.

翻了热茶 2025-01-01 08:50:43

你可以做到...
(至少在 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)

You can do it...
( at least on Linux )
What happens is that your window is being un-decorated then "decorated" with a header bar ( which happens to have a bloody "show_close_button", so I guess this is an intended use )

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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文