简体   繁体   中英

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 :(

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)...

ebTooltip.hide()

Hope that solves your issue!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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