PyGTK 更改彈出式選單的主題

PyGTK 更改彈出式選單的主題

我花了幾個小時在谷歌上搜索,現在放棄了...

我需要更改應用程式中彈出式選單的背景。它設定為任何系統預設主題...並且我需要始終將其設定為 Radiance。

有什麼想法如何實現這個目標?

這是它現在的樣子,並且需要是淺色的

答案1

我的彈出視窗主題如下:

#Use Css themes
css = Gtk.CssProvider()
css.load_from_data("""
        .popup {background-color: rgba(0,0,0,0); border: 0px rgba(255,255,255,0);  border-radius: 14px; border-width: 0;  }
    """ 
Gtk.StyleContext.add_provider_for_screen(Gdk.Screen.get_default(), css,
        Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)

#Get popup parent and set rgba visual so I can do transparency
pwindow=self.popup.get_parent()
screen=pwindow.get_screen()
pwindow.set_visual(screen.get_rgba_visual())

#Give popups the popup CSS class
self.popup.get_style_context().add_class('popup')

我還使用 cairo 來繪製彈出視窗並給它一個漂亮的紋理。為此,我只需將其“繪製”訊號連接到回調即可。

我會查看 Radiance Gtk 主題來找出背景顏色是什麼,並將其用於背景顏色 css 設定。您可以在 中找到它/usr/share/themes/Radiance/Gtk-3.0/gtk.css。如果您不需要透明度,請跳過上面的 pwindow 內容,只需將 style_context 添加到彈出視窗中。

相關內容