2016-02-12 143 views
1

我想讓我的按鈕在我的HMI透明的,但我沒能找到任何功能,能做到這一點!化妝小工具(按鈕)透明GTK

使用下面的代碼,我只能讓我的背景透明的,但不是組件。

Button = gtk_button_new_with_label ("MyButton"); 
gtk_window_set_opacity(GTK_Widget(Button), 0.3); 

你能幫我嗎?

回答

0

在這種情況下,當讀取此功能的python文檔(我知道您使用C但不應該是一個問題)時,問題很可能依賴於OS,它提到了關於窗口系統功能的一些評論。

set_opacity(不透明度)[source]

參數:

  • 不透明度(浮動) - 所需的不透明度,0和1

請求之間的self是部分呈現 tran sparent,不透明度0爲完全透明,完全1不透明 。 (不透明度值被限制在[0,1]範圍內)。這工作 兩個頂層窗口小部件,和子部件,雖然有一定的侷限性 :

對於頂級部件,這取決於有窗口 系統的能力。在X11這個只對具有 合成管理運行X屏幕任何影響。見Gtk.Widget.is_composited()。在 的Windows應該總是工作,雖然窗口後設置窗口的透明度 已被證明會導致它在Windows上一次閃爍。

對於孩子部件,如果任何受影響的部件有一個本地 窗口它不工作,或禁用雙緩衝。

所以假設你還是希望有一個透明的按鈕,當然,你可以根據自己在組合Gtk.ImageEventBoxbutton-press-eventbutton-release-event信號的自定義按鈕。您可以在其中使用任何圖像和不透明度。

正如我更成Python的人的例子是在Python,但它應該是相當容易複製它在C:

class ImageButton(Gtk.EventBox): 
    def __init__(self): 
     super(Gtk.EventBox, self).__init__() 

     # Load the images for the button 
     self.button_image = Gtk.Image.new_from_icon_name("edit-delete", Gtk.IconSize.MENU) 
     self.button_pressed_image = Gtk.Image.new_from_icon_name("edit-delete-symbolic", Gtk.IconSize.MENU) 

     # Add the default image to the event box 
     self.add(self.button_image) 

     # Connect the signal listeners 
     self.connect('realize', self.on_realize) 
     self.connect('button-press-event', self.on_button_pressed) 
     self.connect('button-release-event', self.on_button_released) 


    def update_image(self, image_widget): 
     self.remove(self.get_child()) 
     self.add(image_widget) 
     self.button_pressed_image.show() 

    def on_realize(self, widget): 
     hand_pointer = Gdk.Cursor(Gdk.CursorType.HAND1) 
     window = self.get_window() 
     window.set_cursor(hand_pointer) 

    def on_button_pressed(self, widget, event): 
     self.update_image(self.button_pressed_image) 

    def on_button_released(self, widget, event): 
     self.update_image(self.button_image)