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 |
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 |
Grant Gayed Messages: 2150 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.
|
|
| |
Goto Forum:
Current Time: Thu Apr 25 14:02:45 GMT 2024
Powered by FUDForum. Page generated in 0.02745 seconds
|