Hi,
I created a listbox item showing an image (see https://sourceforge.net/tracker/index.p ... tid=605424). But I like to show a tooltip with a short description when the user moves the mouse cursor over the image, how can I do this, ListboxItem can't handle events and has no method like setTooltipText().
Tooltips in Listboxes
Moderators: CEGUI MVP, CEGUI Team
- Blakharaz
- Not too shy to talk
- Posts: 31
- Joined: Wed Jan 12, 2005 12:06
- Location: Potsdam, Germany
- Contact:
Tooltips in Listboxes
Coder in the Pantheon Team - creators of "Rastullahs Lockenpracht" (http://www.rastullahs-lockenpracht.de/)
- CrazyEddie
- CEGUI Project Lead
- Posts: 6760
- Joined: Wed Jan 12, 2005 12:06
- Location: England
- Contact:
Re: Tooltips in Listboxes
Hi,
Thanks for the patch
"real" per-item tooltips in the current listbox style widgets are not available - mainly due to the fact that, as you mentioned, the items have no event handling (because they are not window based). At some stage, I would still like to see these widgets be transitioned over to Window based items like we have for the menu system, anyway, that does not help you at the moment
The best I can suggest is to modify (or even sub-class) the listbox and add some logic to set the main Listbox tooltip text to something related to whatever item is under the mouse. So you'd basically be writing a MouseMove handler using logic similar to what we use for the MouseButtonDown handler - except that rather than selecting the item, you just grab some text you define in it and set that text as the Listbox tooltip.
Not ideal, but at the moment, I think it's the best you can do. If you need further clarification of this approach, somebody should be able to assist
Thanks for the patch
"real" per-item tooltips in the current listbox style widgets are not available - mainly due to the fact that, as you mentioned, the items have no event handling (because they are not window based). At some stage, I would still like to see these widgets be transitioned over to Window based items like we have for the menu system, anyway, that does not help you at the moment
The best I can suggest is to modify (or even sub-class) the listbox and add some logic to set the main Listbox tooltip text to something related to whatever item is under the mouse. So you'd basically be writing a MouseMove handler using logic similar to what we use for the MouseButtonDown handler - except that rather than selecting the item, you just grab some text you define in it and set that text as the Listbox tooltip.
Not ideal, but at the moment, I think it's the best you can do. If you need further clarification of this approach, somebody should be able to assist
Useful Links: Forum Guidelines | Documentation | Tutorials | HOWTO | Videos | Donate to CEGUI | CEGUI Twitter
- Blakharaz
- Not too shy to talk
- Posts: 31
- Joined: Wed Jan 12, 2005 12:06
- Location: Potsdam, Germany
- Contact:
Re: Tooltips in Listboxes
Okay, I tried to do this. But it seems that tooltips are not resized very often (and I found no auto-resize like in the menus).
My code is
Additionally ListboxItem has the new method getTooltipText().
The result is often like this:
Seldom (I don't know when and why) I get:
Mouse over first item:
Mouse over second item:
Is there any possibility to force a resize of the tooltip popup? Or do I make an other mistake?
Maybe the tooltip should follow the mouse pointer?
BTW: I also have a listbox text component with word wrapping, maybe this could be integrated into CEGUI too?
My code is
Code: Select all
void Listbox::onMouseMove(MouseEventArgs& e)
{
Point posi = relativeToAbsolute(screenToWindow(e.position));
ListboxItem* item = getItemAtPoint(posi);
if (item != NULL)
{
setTooltipText(item->getTooltipText());
}
else
{
setTooltipText("");
}
Window::onMouseMove(e);
}
Additionally ListboxItem has the new method getTooltipText().
The result is often like this:
Seldom (I don't know when and why) I get:
Mouse over first item:
Mouse over second item:
Is there any possibility to force a resize of the tooltip popup? Or do I make an other mistake?
Maybe the tooltip should follow the mouse pointer?
BTW: I also have a listbox text component with word wrapping, maybe this could be integrated into CEGUI too?
Coder in the Pantheon Team - creators of "Rastullahs Lockenpracht" (http://www.rastullahs-lockenpracht.de/)
- CrazyEddie
- CEGUI Project Lead
- Posts: 6760
- Joined: Wed Jan 12, 2005 12:06
- Location: England
- Contact:
Re: Tooltips in Listboxes
Hi,
I'll make two modifications for you:
1) When the tool-tip text is changed, I'll make the Tooltip reposition and recalculate its size.
2) Make the Tooltip::positionSelf method public. Then when you respond to mouse movements in Listbox you can do:
and the tooltip should then follow the mouse.
I'll do this in a little while, commit to CVS and either post a patch here or on IRC if I see you there
Edit:
Here is the patch. This is pretty much non-breaking so I'll add it in all branches from v0-3 and up.
I'll make two modifications for you:
1) When the tool-tip text is changed, I'll make the Tooltip reposition and recalculate its size.
2) Make the Tooltip::positionSelf method public. Then when you respond to mouse movements in Listbox you can do:
Code: Select all
getTooltip()->positionSelf();
and the tooltip should then follow the mouse.
I'll do this in a little while, commit to CVS and either post a patch here or on IRC if I see you there
Edit:
Here is the patch. This is pretty much non-breaking so I'll add it in all branches from v0-3 and up.
Code: Select all
Index: include/elements/CEGUITooltip.h
===================================================================
RCS file: /cvsroot/crayzedsgui/cegui_mk2/include/elements/CEGUITooltip.h,v
retrieving revision 1.7
diff -u -r1.7 CEGUITooltip.h
--- include/elements/CEGUITooltip.h 21 Aug 2005 17:57:02 -0000 1.7
+++ include/elements/CEGUITooltip.h 30 Aug 2005 09:09:47 -0000
@@ -167,6 +167,16 @@
*/
void setFadeTime(float seconds);
+ //
+ /*!
+ \brief
+ Causes the tooltip to position itself appropriately.
+
+ \return
+ Nothing.
+ */
+ void positionSelf(void);
+
protected:
/*************************************************************************
Implementation Methods
@@ -189,9 +199,6 @@
void switchToFadeInState(void);
void switchToFadeOutState(void);
- // method to get the tooltip to position itself appropriately.
- void positionSelf(void);
-
/*!
\brief
@@ -288,6 +295,7 @@
************************************************************************/
void updateSelf(float elapsed);
void onMouseEnters(MouseEventArgs& e);
+ void onTextChanged(WindowEventArgs& e);
/************************************************************************
Enumerations
Index: src/elements/CEGUITooltip.cpp
===================================================================
RCS file: /cvsroot/crayzedsgui/cegui_mk2/src/elements/CEGUITooltip.cpp,v
retrieving revision 1.3
diff -u -r1.3 CEGUITooltip.cpp
--- src/elements/CEGUITooltip.cpp 10 Jul 2005 09:39:00 -0000 1.3
+++ src/elements/CEGUITooltip.cpp 30 Aug 2005 09:09:47 -0000
@@ -363,6 +363,19 @@
Window::onMouseEnters(e);
}
+ void Tooltip::onTextChanged(WindowEventArgs& e)
+ {
+ // base class processing
+ Window::onTextChanged(e);
+
+ // set size and potition of the tooltip window to consider new text
+ setSize(Absolute, getTextSize());
+ positionSelf();
+
+ // we do not signal we handled it, in case user wants to hear
+ // about text changes too.
+ }
+
void Tooltip::onHoverTimeChanged(WindowEventArgs& e)
{
fireEvent(EventHoverTimeChanged, e, EventNamespace);
Useful Links: Forum Guidelines | Documentation | Tutorials | HOWTO | Videos | Donate to CEGUI | CEGUI Twitter
- Blakharaz
- Not too shy to talk
- Posts: 31
- Joined: Wed Jan 12, 2005 12:06
- Location: Potsdam, Germany
- Contact:
Re: Tooltips in Listboxes
Okay, it's almost done.
But I noticed a little bug with the tooltip: If the mouse pointer is not over an item, I change the text to "" which hides the tooltip. But if I go over an item again, the tooltip won't show again, I have to leave the listbox and come back into it.
But I noticed a little bug with the tooltip: If the mouse pointer is not over an item, I change the text to "" which hides the tooltip. But if I go over an item again, the tooltip won't show again, I have to leave the listbox and come back into it.
Coder in the Pantheon Team - creators of "Rastullahs Lockenpracht" (http://www.rastullahs-lockenpracht.de/)
- CrazyEddie
- CEGUI Project Lead
- Posts: 6760
- Joined: Wed Jan 12, 2005 12:06
- Location: England
- Contact:
Re: Tooltips in Listboxes
I shall attempt to resolve this final issue this morning.
This has given the tooltips system a good testing so thanks for that, because I've been able to shake out a few issues
Edit:
As mentioned on IRC - This is a kind of half-bug, depending upon your point of view, and what behaviour is expected from tooltips when used 'normally'. Anyway, as always, there is a workaround, and this is it:
Basically, within the Listbox::onMouseMove handler, you need a couple of extra lines.
Currently, you probably have something similar to this in there, to make the tooltip follow the mouse:
All you need to do is modify that to something similar to this:
This will re-activate the tooltip for the window (listbox).
HTH
This has given the tooltips system a good testing so thanks for that, because I've been able to shake out a few issues
Edit:
As mentioned on IRC - This is a kind of half-bug, depending upon your point of view, and what behaviour is expected from tooltips when used 'normally'. Anyway, as always, there is a workaround, and this is it:
Basically, within the Listbox::onMouseMove handler, you need a couple of extra lines.
Currently, you probably have something similar to this in there, to make the tooltip follow the mouse:
Code: Select all
Tooltip* tooltip = getTooltip();
if (tooltip)
tooltip->positionSelf();
All you need to do is modify that to something similar to this:
Code: Select all
Tooltip* tooltip = getTooltip();
if (tooltip)
{
if (tooltip->getTargetWindow() != this)
tooltip->setTargetWindow(this);
else
tooltip->positionSelf();
}
This will re-activate the tooltip for the window (listbox).
HTH
Useful Links: Forum Guidelines | Documentation | Tutorials | HOWTO | Videos | Donate to CEGUI | CEGUI Twitter
- Blakharaz
- Not too shy to talk
- Posts: 31
- Joined: Wed Jan 12, 2005 12:06
- Location: Potsdam, Germany
- Contact:
Re: Tooltips in Listboxes
Setting the tooltip's owner did the trick. Thanks for your help. I submitted a patch against the 0.4 CVS branch on SourceForge.
Coder in the Pantheon Team - creators of "Rastullahs Lockenpracht" (http://www.rastullahs-lockenpracht.de/)
- CrazyEddie
- CEGUI Project Lead
- Posts: 6760
- Joined: Wed Jan 12, 2005 12:06
- Location: England
- Contact:
Re: Tooltips in Listboxes
Cool. Glad it's working properly now, and thanks for the patch. I'll have a look later today with any luck.
Useful Links: Forum Guidelines | Documentation | Tutorials | HOWTO | Videos | Donate to CEGUI | CEGUI Twitter
Return to “Modifications / Integrations / Customisations”
Who is online
Users browsing this forum: No registered users and 3 guests