Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Make widget transient for tooltip mouseover
Make widget transient for tooltip mouseover [message #754267] Tue, 01 November 2011 17:08 Go to next message
Simon L. is currently offline Simon L.
Messages: 22
Registered: January 2010
Junior Member
Hi,
Today, I was creating a custom widget (it is a composite with some widgets in it), and tried to make happen that if the user hovers with the mouse over the whole thing, the tooltip of the enclosing composite is shown, even if the pointer is over one of the inner widgets (which do not have the tooltip set).
All in all, I want to make the inner widgets transient to the mouse-hovering-tooltip behaviour. Unfortunately, just setting the tooltip for all the inner widgets is not quite good enough, becouse the tooltip window jumps around when moving the mouse from one inner widget to another, so the look'n'feel is not consistent with all the other SWT widgets.

I tried around with it quite some while, and searched the net for it, but found nothing :/ Please help if you know how to do this, thanks =)

Simon L.
Re: Make widget transient for tooltip mouseover [message #754292 is a reply to message #754267] Tue, 01 November 2011 20:57 Go to previous messageGo to next message
Grant Gayed is currently offline Grant Gayed
Messages: 2151
Registered: July 2009
Senior Member
Hi Simon,

The only time that events propogate up the swt widget hierarchy is if a
control is disabled, which I don't think is the case for you. So there
isn't a way to let the event pass through to the parent.

You need to handle the displaying of the tooltip yourself. This is
demonstrated in the snippet below.

public static void main(String[] args) {
final Display display = new Display();
Shell shell = new Shell(display);
shell.setBounds(10,10,200,200);
shell.setToolTipText("Shell's tooltip text");
Composite c1 = new Composite(shell, SWT.BORDER);
c1.setBounds(10,10,80,80);
Composite c2 = new Composite(shell, SWT.BORDER);
c2.setBounds(100,100,80,80);
Listener listener = new Listener() {
public void handleEvent(Event event) {
Composite composite = (Composite)event.widget;
ToolTip tip = new ToolTip(composite.getShell(), SWT.NONE);
tip.setMessage(composite.getParent().getToolTipText());
tip.setLocation(display.map(composite, null, new
Point(event.x, event.y)));
tip.setVisible(true);
}
};
c1.addListener(SWT.MouseHover, listener);
c2.addListener(SWT.MouseHover, listener);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
display.dispose();
}

Grant


On 11/1/2011 1:08 PM, Simon L. wrote:
> Hi,
> Today, I was creating a custom widget (it is a composite with some
> widgets in it), and tried to make happen that if the user hovers with
> the mouse over the whole thing, the tooltip of the enclosing composite
> is shown, even if the pointer is over one of the inner widgets (which do
> not have the tooltip set). All in all, I want to make the inner widgets
> transient to the mouse-hovering-tooltip behaviour. Unfortunately, just
> setting the tooltip for all the inner widgets is not quite good enough,
> becouse the tooltip window jumps around when moving the mouse from one
> inner widget to another, so the look'n'feel is not consistent with all
> the other SWT widgets.
>
> I tried around with it quite some while, and searched the net for it,
> but found nothing :/ Please help if you know how to do this, thanks =)
>
> Simon L.
Re: Make widget transient for tooltip mouseover [message #754300 is a reply to message #754292] Tue, 01 November 2011 23:52 Go to previous message
Simon L. is currently offline Simon L.
Messages: 22
Registered: January 2010
Junior Member
Hi Grant Gayed,
Thanks for your fast reply. Very useful to know that there is no way to do it the way I intended to do first. I will handle the tooltip display manually, as you suggested. Many thanks =)
Previous Topic:Tooltip on Text
Next Topic:Cairo on HPUX. "Unable to load graphics library" Exception when running SWT application on
Goto Forum:
  


Current Time: Wed Sep 24 00:41:35 GMT 2014

Powered by FUDForum. Page generated in 0.11327 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software