0

gtk3を使用して、デフォルトのGtkWindowタイトルバーの色を変更するにはどうすればよいですか?それはGtkStyleContextを含みますか?私はGtkCssProviderのみを使用しました。

4

2 に答える 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 に答える