gtk3 GtkWindow title bar color

跟風遠走 提交于 2019-12-12 03:23:28

问题


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


回答1:


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.




回答2:


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)


来源:https://stackoverflow.com/questions/8772811/gtk3-gtkwindow-title-bar-color

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!