GNOME Bugzilla – Bug 541296
Failing to remove a tooltip with GTKMM-2.12
Last modified: 2011-07-20 10:17:59 UTC
Using GTKMM 2.12.7/GTK-2.12.9 I can set/change a tool-tip for a widget with Gtk::Widget::set_tooltip_text ("Text"). What fails is removing the tool-tip. Both set_tooltip_text (Glib::ustring ()) and set_tooltip_text ("") only remove its text, but not the tool-tip itself (i.e. hoovering the mouse over the widget in question displays a small, empty (yellow) window). When I call the respective GTK-function gtk_widget_set_tooltip_text (widget.gobj (), NULL) this works as expected (i.e. no tool-tip window is displayed). Of course I can't call Gtk::Widget::set_tooltip_text (NULL) as this causes an exception (in Glib::ustring). As a side-note: The deprecated Gtk::Tooltips::unset_tip also does not work (but did work, probably up to GTKMM 2.12) Another side-note: The same problem might occur with Gtk::Widget::set_tooltip_window (), though I didn't check that. Workarounds: Use the aforementioned gtk_widget_set_tooltip_text.
what about Gtk::Widget::set_has_tooltip(false)? Does this do what you want?
I guess we should check for "" and use NULL in that case in our implementation. A patch would be welcome. Or you could patch GTK+, which should really check for this itself.
Created attachment 113881 [details] [review] provide unset_*() methods for tooltip-related functionality actually, I think we should probably provide unset_ methods for these things rather than checking for an empty string since the same issue will be true of the other properties of the tooltip (e.g. Tooltip::set_custom_widget(), set_icon(), etc). In all of these cases, passing a NULL parameter, will disable that UI element. So we may as well provide the same interface for the text one as well. Here's a patch that does this. What do you think?
To answer comment #1: Gtk::Widget::set_has_tooltip(false) does work (i.e. remove the tooltip-widget)! Thanks for the (incredible) fast reply!
Yeah, the unsets probably make it even more explicit, though I still think that GTK+ just shouldn't ever show an empty tooltip.
well, we could provide the unset_ methods *and* check for an empty string in set_text(). But that would mean that you could set an empty string in GTK+ and not in gtkmm. And even though it's strange to have an empty tooltip, I guess I'd rather not disallow something that can be accomplished in GTK+ unless I know for certain why they allow it.
I created a patch for GTK+ in bug #541399.
Murray, what about the patch that I attached here? It seems that it's still good API to add, even if the fix to GTK+ fixed the immediate issue.
What would be unclear about set*("") or set*(Glib::ustring())? It seems like we'd have to add a lot of unset*() methods here.
Jonathon, do you have an opinion?
Jonathon?
The unset methods don't seem particularly useful.(In reply to comment #3) > Created an attachment (id=113881) [details] [review] > provide unset_*() methods for tooltip-related functionality I have applied the Tooltip::unset_*() part of this, though not the unset_tip_area() because the C documentation does not say that it can be NULL or what that would mean: http://git.gnome.org/browse/gtkmm/commit/?id=654b19a38cb820b5d18aa5d10256b162813bdf50 This is particularly useful for unsetting the icon, so it makes sense there, but I'm not sure if it's really useful for methods that can take "", now that the C implementation has been fixed to handle "" like NULL.