简体   繁体   English

当光标悬停在上面时,我可以使自定义pygtk工具提示保持打开状态吗?

[英]Can I make a custom pygtk tooltip stay on when the cursor is over it?

Please look at the following snippet : 请查看以下代码段:

    import gtk

    def callback(widget, x, y, keyboard_mode, tooltip):
        hbox = gtk.HBox(False, 8)
        button = gtk.Button('Exit Tooltip')
        label = gtk.Label('Tooltip text')
        hbox.pack_start(label)
        hbox.pack_start(button)
        hbox.show_all()
        tooltip.set_custom(hbox)
        return True

    label = gtk.Label('Test label')
    label.set_has_tooltip(True)
    label.connect('query-tooltip', callback)

Here I've created a custom tooltip with a close button in it. 在这里,我创建了一个带有关闭按钮的自定义工具提示 Now I want it to stay until i click that close button . 现在,我希望它一直保持到我单击该关闭按钮 Searching google was not that helpful. 搜索谷歌不是那么有用。 besides I would also like to know the signals/events that are emitted when a tooltip is being closed. 此外,我还想知道在关闭工具提示时发出的信号/事件

Similar problems are handled smoothly for JQuery/JavaScript/Ajax tooltips etc. but for gtk/pygtk there is no luck :( 对于JQuery / JavaScript / Ajax工具提示等,类似的问题也可以顺利处理,但是对于gtk / pygtk来说没有运气:(

Thanks in advance ... 提前致谢 ...

I had this issue as well, and as far as I know, there isn't any way to determine how long a tooltip stays up. 我也遇到了这个问题,据我所知,没有任何方法可以确定工具提示的停留时间。

What I did (and recommend to you) is that you make your own "tooltip" and set it's background color to yellow, or whatever color you want, via an eventbox. 我所做的(并向您推荐)是您制作自己的“工具提示”,并通过事件框将其背景颜色设置为黄色,或将其设置为所需的任何颜色。 Make sure you don't show it yet. 确保您没有显示它。 This is just a simplified code, as you will need to position and size this in your project yourself. 这只是一个简化的代码,因为您需要自己在项目中定位和调整大小。

color = gtk.gdk.rgb_get_colormap().alloc_color('black')
ebTooltip = gtk.EventBox()
btnTooltip = gtk.Button("Close")
ebTooltip.add(btnTooltip)
ebTooltip.modify_bg(gtk.STATE_NORMAL, color)

Now, you just need to hide and show this eventbox via your callbacks. 现在,您只需要通过回调隐藏和显示此事件框。 To show it, call... 要显示它,请致电...

ebTooltip.show()

And, to hide it (probably on the "clicked" event of your close button)... 并且,将其隐藏(可能在关闭按钮的“ clicked”事件上)...

ebTooltip.hide()

Hope that solves your issue! 希望能解决您的问题!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM