How to copy widget GTK style and apply it to another?

My current GTK popups look like this: note that a dark atmosphere theme requires color.

pic

In GTK3.8 and later versions of GTKMenuButtons , the popup looks like this: note that it looks like it uses style buttons.

pic

I like this style and I want the pop-ups of my application to look the same, so there is a better look - integration and feeling.

I know I can override the pop-up background color using this python code snippet:

style = button.get_style_context ()
color = style.get_background_color (Gtk.StateFlags.NORMAL)
popup_menu.override_background_color (Gtk.StateFlags.NORMAL, color)

It looks like this if I apply a button background color.

pic

, .

, - 1px wide?

, - ( ) - CSS ( ) , menubutton

- GTKMenuButton gtkmenubutton.c - , , menubutton .

+1
2

, ( ) .

:

MenuButton, .

StyleClass Grid , .

style = grid.get_style_context()
style.add_class(Gtk.STYLE_CLASS_TOOLBAR)

:

Imgur

from gi.repository import Gtk

class MenuExampleWindow(Gtk.Window):

    def __init__(self):
        Gtk.Window.__init__(self, title="Menu Example")

        self.set_default_size(200, 200)

        grid = Gtk.Grid()
        grid.insert_column(0)

        menu = Gtk.Menu()
        mitem1 = Gtk.MenuItem(label = "Item 1")
        mitem2 = Gtk.MenuItem(label = "Item 2")


        menub = Gtk.MenuButton(label='menu')
        menub.set_popup(menu)
        menub.set_align_widget(None)
        menub.show_all()

        menu.append(mitem1)
        menu.append(mitem2)
        menu.attach_to_widget(menub, None)
        menu.show_all()

        style = grid.get_style_context()
        style.add_class(Gtk.STYLE_CLASS_TOOLBAR)


        grid.attach(menub, 0,0,1,1)
        self.add(grid)

window = MenuExampleWindow()       
window.connect("delete-event", Gtk.main_quit)
window.show_all()
Gtk.main()

+1

, gtk3 +

gtk_widget_get_style/gtk_widget_get_modifier_style gtk_widget_set_style/gtk_widget_modify_style , . , , , (. DocBook )

0

Source: https://habr.com/ru/post/1650794/


All Articles