Gtk Treeview query tooltip - hide if blank for cell

Hi
I have setup a tooltip for a gtkview (liststore) in gtk3-perl
It all works fine except if there is no tooltip text an ugly black rectangle shows up. Is there a way to hide this.


$widgete{controlview}->signal_connect('query-tooltip'=>sub{
        ($sopts->{view},$sopts->{xpos},$sopts->{ypos},$sopts->{key},$sopts->{tooltip})=@_;
	$sopts->{colh}=\%colh;
	encode_gui_tooltip($sopts);
	return 1;
	}
	);


sub encode_gui_tooltip {
	my ($sopts)=@_;
	my ($view,$xpos,$ypos,$key,$tooltip)=
	($sopts->{view},$sopts->{xpos},$sopts->{ypos},$sopts->{key},$sopts->{tooltip});
	my ($bin_x, $bin_y) = $view->convert_widget_to_bin_window_coords($xpos, $ypos);
		my @path = $view->get_path_at_pos($bin_x,$bin_y);
		my ($row,$colno);
		if ($path[0]){
			$row=$path[0]->to_string;
		}

		if ($path[1]){
			$colno=$sopts->{colh}->{$path[1]->get_title};
		}
$actions{2}->{3}->{cmd}=sub{
				#elsif ($colno==3){
					my $option;
				$option=$sopts->{controlmodel}->get($sopts->{controlmodel}->get_iter_from_string(2),3);
				if (!($option )){
					$option=q{}
				}
				 $tooltip->set_text($option);
				 $view->set_tooltip_cell($tooltip, $path[0], $path[1])
				};

			if ($actions{$row}->{$colno}->{cmd}){
				&{$actions{$row}->{$colno}->{cmd}}
			}
			else {
				no warnings ;
				#my $tooltip=undef;
				$tooltip->set_custom(undef);
				#$tooltip->set_text(undef);
				#$tooltip->set_icon(undef);
				#$view->set_tooltip_cell(undef);
				#$view->set_tooltip_cell($tooltip, $path[0], $path[1]);
				return 0
				};

As can be see I’ve tried various approaches so far with no success. Setting tooltip to undef works but spews out loads of messages from Glib::Introspection
unhandled exception in callback:
*** undef is not of type Gtk3::Tooltip at /usr/lib64/perl5/vendor_perl/Glib/Object/Introspection.pm line 67.
*** ignoring at /usr/share/perl5/vendor_perl/Gtk3.pm line 572.

Returning FALSE should hide the tooltip. You can also use an empty string. If neither of these work, then there’s something wrong with either GTK or with your code.

You cannot set $tooltip to undef because you’re literally overwriting data that does not belong to you; the Tooltip object is owned by the widget.

Thanks, I had the return in the query-tooltip callback, while returning 0 in the callback function.
Removing that and putting return values as appropriate fixed it.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.