【问题标题】:Making popup GtkMenu transparent and borderless in python Gtk3在python Gtk3中使弹出GtkMenu透明且无边框
【发布时间】:2012-08-18 21:25:14
【问题描述】:

我在使用 Python 和 Gtk3 制作无边框和透明的弹出菜单时遇到了问题。使用相同的代码,我可以使我的主窗口和消息对话框具有适当的样式,那么我的代码有什么问题?在 CSS 定义中添加border-style: none (或如下所示的每一边) 只会删除底部边框。这是我所拥有的屏幕截图。您可以在后面看到格式正确的主窗口。 Cairo 正在正确绘制弹出窗口的背景(注意白色矩形内的圆角,但它不透明)

          

编辑我能够通过获取Gtk.Menu 的父级并在其上设置/绘图来使菜单透明。但我一直无法摆脱顶部、左侧和右侧的边框。只是底部。

以下是相关代码:

def __init__(self):
   ....#other code...

   css.load_from_data("""
        .title { background-color: rgba(255, 255, 255, 0); color: rgba(%s,1);}
        .iconview { background-color: rgba(255, 255, 255, 0); color: rgba(%s,1); font-size:%i}
        .background2 { background-color: rgba(%s,0.7);  color: rgba(%s, 1);border-top-style:none; border-left-style:none; border-right-style:none; border-bottom-style:none;}
    """ % (str(sel f.FONT_rgb).strip('[]'),str(self.FONT_rgb).strip('[]'),FONTSIZE,str(self.BG_rgb).strip('[]'),str(self.FONT_rgb).strip('[]')))
    Gtk.StyleContext.add_provider_for_screen(Gdk.Screen.get_default(), css,
        Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)

    parent=self.popup.get_parent()
    screen=parent.get_screen()

    parent.set_visual(screen.get_rgba_visual())
    parent.set_app_paintable(True)
    parent.get_style_context().add_class('background2')

    for child in self.popup.get_children():
        child.get_style_context().add_class('iconview')
        child.set_app_paintable(True)
    self.popup.get_style_context().add_class('iconview')
    self.popup.set_app_paintable(True)

    parent.connect("draw", self.draw_window_cb)

def on_mouse_click(self,widget, event):
    # Check if right mouse button was preseed
    if event.type == Gdk.EventType.BUTTON_RELEASE and self.dragging==False:

        if event.button == 3 and path != None:
            self.popup.popup(None, None, None, None, event.button, event.time)

【问题讨论】:

    标签: python user-interface cairo gtk3


    【解决方案1】:

    试试:

    border-radius: 15       
    border-width: 0
    

    【讨论】:

    • 不好。我试过了。我能做的唯一工作是使半径尽可能接近开罗绘制的半径。但是,你仍然可以看到,上、左、右边框比下边框厚一点(这是唯一受 0px 宽度影响的)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-04-02
    • 1970-01-01
    • 2011-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多