化妆小工具(按钮)透明GTK
问题描述:
我想让我的按钮在我的HMI透明的,但我没能找到任何功能,能做到这一点!化妆小工具(按钮)透明GTK
使用下面的代码,我只能让我的背景透明的,但不是组件。
Button = gtk_button_new_with_label ("MyButton");
gtk_window_set_opacity(GTK_Widget(Button), 0.3);
你能帮我吗?
答
在这种情况下,当读取此功能的python文档(我知道您使用C但不应该是一个问题)时,问题很可能依赖于OS,它提到了关于窗口系统功能的一些评论。
set_opacity(不透明度)[source]
参数:
- 不透明度(浮动) - 所需的不透明度,0和1
请求之间的
self
是部分呈现 tran sparent,不透明度0为完全透明,完全1不透明 。 (不透明度值被限制在[0,1]范围内)。这工作 两个顶层窗口小部件,和子部件,虽然有一定的局限性 :对于*部件,这取决于有窗口 系统的能力。在X11这个只对具有 合成管理运行X屏幕任何影响。见
Gtk.Widget.is_composited()
。在 的Windows应该总是工作,虽然窗口后设置窗口的透明度 已被证明会导致它在Windows上一次闪烁。对于孩子部件,如果任何受影响的部件有一个本地 窗口它不工作,或禁用双缓冲。
所以假设你还是希望有一个透明的按钮,当然,你可以根据自己在组合Gtk.Image
与EventBox
和button-press-event
和button-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)