【问题标题】:gtk3 GtkWindow title bar colorgtk3 GtkWindow 标题栏颜色
【发布时间】:2012-01-07 20:22:39
【问题描述】:

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

【问题讨论】:

    标签: gtk3 custom-titlebar


    【解决方案1】:

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

    【讨论】:

    • 通过 GtkThemingEngine 怎么样? link
    • 不,那是用于设置 GTK 窗口内容的样式。还是和窗口管理器无关。
    【解决方案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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-02
      • 2013-05-22
      • 2011-10-22
      • 1970-01-01
      相关资源
      最近更新 更多