[Gtk-sharp-list] Using Tooltips QueryTooltipHandler

Cody Russell bratsche at gnome.org
Sat Jan 3 13:57:57 EST 2009


Hi Wolfgang,

Your second example (the one that is working) is not right.  Your first
example was right, but it looked like you had some typos in the email
because that code should not compile as-is.

Here is a working example that's using a dynamic tooltip:


using System;
using Gtk;

namespace TooltipTest
{
  class MainClass
  {
    public static void Main (string[] args)
    {
      Application.Init ();
      MainWindow win = new MainWindow ();

      VBox box = new VBox();
      win.Add(box);

      Label label = new Label("Testing Tooltip");
      box.PackStart(label);

      label.HasTooltip = true;
      label.QueryTooltip += new QueryTooltipHandler(query_tooltip);

      win.ShowAll ();
      Application.Run ();
    }
		
    private static void query_tooltip(object sender, QueryTooltipArgs e)
    {
      e.Tooltip.Text = "query_tooltip called " + foo.ToString() + "
times";
      e.RetVal = true;
			
      foo++;
    }
		
    private static int foo = 1;
  }
}


On Sat, 2009-01-03 at 15:49 +0100, Wolfgang Mauer wrote:
> Hi all,
> i want to use "dynamic" tooltips with the QueryTooltipHandler.
> Can anyone explain how this works right?
> 
> I have tryed 
> 
> this.mywidget.HasTooltip = true;
> this.mywidget.QueryTooltip += new QueryTooltipHandler(mywidgettooltip);
> 
> ...
> 
> public void mywidgettooltip(object sender, QueryTooltipArgs args)
> {
> 	args.args.Tooltip.Text = this.ToolTipText;
> 	args.RetVal = true;
> }
> 
> but the Text will not be displayed.
> 
> if i use 
> public void mywidgettooltip(object sender, QueryTooltipArgs args)
> {
> 	(sender as Entry).TooltipText = this.ToolTipText;
> 	args.RetVal = true;
> }
> it works!
> 
> is this the right way to set the tooltip?
> /
> Wolfgang
> 
> 



More information about the Gtk-sharp-list mailing list