Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions

TQToolTip Class Reference

The TQToolTip class provides tool tips (balloon help) for any widget or rectangular part of a widget. More...

#include <qtooltip.h>

Inherits TQt.

List of all member functions.

Public Members

Static Public Members

Protected Members


Detailed Description

The TQToolTip class provides tool tips (balloon help) for any widget or rectangular part of a widget.

The tip is a short, single line of text reminding the user of the widget's or rectangle's function. It is drawn immediately below the region in a distinctive black-on-yellow combination.

The tip can be any Rich-Text formatted string.

TQToolTipGroup provides a way for tool tips to display another text elsewhere (most often in a status bar).

At any point in time, TQToolTip is either dormant or active. In dormant mode the tips are not shown and in active mode they are. The mode is global, not particular to any one widget.

TQToolTip switches from dormant to active mode when the user hovers the mouse on a tip-etquipped region for a second or so and remains active until the user either clicks a mouse button, presses a key, lets the mouse hover for five seconds or moves the mouse outside all tip-etquipped regions for at least a second.

The TQToolTip class can be used in three different ways:

  1. Adding a tip to an entire widget.
  2. Adding a tip to a fixed rectangle within a widget.
  3. Adding a tip to a dynamic rectangle within a widget.

To add a tip to a widget, call the static function TQToolTip::add() with the widget and tip as arguments:

        TQToolTip::add( tquitButton, "Leave the application" );
    

This is the simplest and most common use of TQToolTip. The tip will be deleted automatically when tquitButton is deleted, but you can remove it yourself, too:

        TQToolTip::remove( tquitButton );
    

You can also display another text (typically in a status bar), courtesy of TQToolTipGroup. This example assumes that grp is a TQToolTipGroup * and is already connected to the appropriate status bar:

        TQToolTip::add( tquitButton, "Leave the application", grp,
                       "Leave the application, prompting to save if necessary" );
        TQToolTip::add( closeButton, "Close this window", grp,
                       "Close this window, prompting to save if necessary" );
    

To add a tip to a fixed rectangle within a widget, call the static function TQToolTip::add() with the widget, rectangle and tip as arguments. (See the tooltip/tooltip.cpp example.) Again, you can supply a TQToolTipGroup * and another text if you want.

Both of these are one-liners and cover the majority of cases. The third and most general way to use TQToolTip retquires you to reimplement a pure virtual function to decide whether to pop up a tool tip. The tooltip/tooltip.cpp example demonstrates this too. This mode can be used to implement tips for text that can move as the user scrolls, for example.

To use TQToolTip like this, you must subclass TQToolTip and reimplement maybeTip(). TQToolTip calls maybeTip() when a tip should pop up, and maybeTip() decides whether to show a tip.

Tool tips can be globally disabled using TQToolTip::setGloballyEnabled() or disabled in groups with TQToolTipGroup::setEnabled().

You can retrieve the text of a tooltip for a given position within a widget using textFor().

The global tooltip font and palette can be set with the static setFont() and setPalette() functions respectively.

See also TQStatusBar, TQWhatsThis, TQToolTipGroup, GUI Design Handbook: Tool Tip, and Help System.


Member Function Documentation

TQToolTip::TQToolTip ( TQWidget * widget, TQToolTipGroup * group = 0 )

Constructs a tool tip object. This is only necessary if you need tool tips on regions that can move within the widget (most often because the widget's contents can scroll).

widget is the widget you want to add dynamic tool tips to and group (optional) is the tool tip group they should belong to.

Warning: TQToolTip is not a subclass of TQObject, so the instance of TQToolTip is not deleted when widget is deleted.

Warning: If you delete the tool tip before you have deleted widget then you need to make sure you call remove() yourself from widget in your reimplemented TQToolTip destructor.

        MyToolTip::~MyToolTip()
        {
            remove( widget );
        }
    

See also maybeTip().

void TQToolTip::add ( TQWidget * widget, const TQString & text ) [static]

Adds a tool tip to widget. text is the text to be shown in the tool tip.

This is the most common entry point to the TQToolTip class; it is suitable for adding tool tips to buttons, checkboxes, comboboxes and so on.

Examples: helpsystem/mainwindow.cpp, qdir/qdir.cpp, scribble/scribble.cpp, and tooltip/tooltip.cpp.

void TQToolTip::add ( TQWidget * widget, const TQString & text, TQToolTipGroup * group, const TQString & longText ) [static]

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Adds a tool tip to widget and to tool tip group group.

text is the text shown in the tool tip and longText is the text emitted from group.

Normally, longText is shown in a status bar or similar.

void TQToolTip::add ( TQWidget * widget, const TQRect & rect, const TQString & text ) [static]

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Adds a tool tip to a fixed rectangle, rect, within widget. text is the text shown in the tool tip.

void TQToolTip::add ( TQWidget * widget, const TQRect & rect, const TQString & text, TQToolTipGroup * group, const TQString & groupText ) [static]

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Adds a tool tip to an entire widget and to tool tip group group. The tooltip will disappear when the mouse leaves the rect.

text is the text shown in the tool tip and groupText is the text emitted from group.

Normally, groupText is shown in a status bar or similar.

void TQToolTip::clear () [protected]

Immediately removes all tool tips for this tooltip's parent widget.

bool TQToolTip::enabled () [static]

This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.

TQFont TQToolTip::font () [static]

Returns the font common to all tool tips.

See also setFont().

TQToolTipGroup * TQToolTip::group () const

Returns the tool tip group this TQToolTip is a member of or 0 if it isn't a member of any group.

The tool tip group is the object responsible for maintaining contact between tool tips and a status bar or something else which can show the longer help text.

See also parentWidget() and TQToolTipGroup.

void TQToolTip::hide () [static]

Hides any tip that is currently being shown.

Normally, there is no need to call this function; TQToolTip takes care of showing and hiding the tips as the user moves the mouse.

bool TQToolTip::isGloballyEnabled () [static]

Returns whether tool tips are enabled globally.

See also setGloballyEnabled().

void TQToolTip::maybeTip ( const TQPoint & p ) [pure virtual protected]

This pure virtual function is half of the most versatile interface TQToolTip offers.

It is called when there is a possibility that a tool tip should be shown and must decide whether there is a tool tip for the point p in the widget that this TQToolTip object relates to. If so, maybeTip() must call tip() with the rectangle the tip applies to, the tip's text and optionally the TQToolTipGroup details and the geometry in screen coordinates.

p is given in that widget's local coordinates. Most maybeTip() implementations will be of the form:

        if ( <something> ) {
            tip( <something>, <something> );
        }
    

The first argument to tip() (a rectangle) must encompass p, i.e. the tip must apply to the current mouse position; otherwise TQToolTip's operation is undefined.

Note that the tip will disappear once the mouse moves outside the rectangle you give to tip(), and will not reappear if the mouse moves back in: maybeTip() is called again instead.

See also tip().

Examples: helpsystem/tooltip.cpp and tooltip/tooltip.cpp.

TQPalette TQToolTip::palette () [static]

Returns the palette common to all tool tips.

See also setPalette().

TQWidget * TQToolTip::parentWidget () const

Returns the widget this TQToolTip applies to.

The tool tip is destroyed automatically when the parent widget is destroyed.

See also group().

void TQToolTip::remove ( TQWidget * widget ) [static]

Removes the tool tip from widget.

If there is more than one tool tip on widget, only the one covering the entire widget is removed.

void TQToolTip::remove ( TQWidget * widget, const TQRect & rect ) [static]

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Removes any tool tip for rect from widget.

If there is more than one tool tip on widget, only the one covering rectangle rect is removed.

void TQToolTip::setEnabled ( bool enable ) [static]

This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.

void TQToolTip::setFont ( const TQFont & font ) [static]

Sets the font for all tool tips to font.

See also font().

void TQToolTip::setGloballyEnabled ( bool enable ) [static]

If enable is TRUE sets all tool tips to be enabled (shown when needed); if enable is FALSE sets all tool tips to be disabled (never shown).

By default, tool tips are enabled. Note that this function affects all tool tips in the entire application.

See also TQToolTipGroup::enabled.

void TQToolTip::setPalette ( const TQPalette & palette ) [static]

Sets the palette for all tool tips to palette.

See also palette().

void TQToolTip::setWakeUpDelay ( int i ) [static]

Sets the wakeup delay for all tooltips to i milliseconds.

TQString TQToolTip::textFor ( TQWidget * widget, const TQPoint & pos = TQPoint ( ) ) [static]

Returns the tool tip text for widget at position pos, or TQString::null if there is no tool tip for the given widget and position.

void TQToolTip::tip ( const TQRect & rect, const TQString & text ) [protected]

Immediately pops up a tip saying text and removes the tip once the cursor moves out of rectangle rect (which is given in the coordinate system of the widget this TQToolTip relates to).

The tip will not reappear if the cursor moves back; your maybeTip() must reinstate it each time.

void TQToolTip::tip ( const TQRect & rect, const TQString & text, const TQString & groupText ) [protected]

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Immediately pops up a tip saying text and removes that tip once the cursor moves out of rectangle rect (which is given in the coordinate system of the widget this TQToolTip relates to). groupText is the text emitted from the group.

The tip will not reappear if the cursor moves back; your maybeTip() must reinstate it each time.

void TQToolTip::tip ( const TQRect & rect, const TQString & text, const TQRect & geometry ) [protected]

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Immediately pops up a tip within the rectangle geometry, saying text and removes the tip once the cursor moves out of rectangle rect. Both rectangles are given in the coordinate system of the widget this TQToolTip relates to.

The tip will not reappear if the cursor moves back; your maybeTip() must reinstate it each time.

If the tip does not fit inside geometry, the tip expands.

void TQToolTip::tip ( const TQRect & rect, const TQString & text, const TQString & groupText, const TQRect & geometry ) [protected]

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Immediately pops up a tip within the rectangle geometry, saying text and removes the tip once the cursor moves out of rectangle rect. groupText is the text emitted from the group. Both rectangles are given in the coordinate system of the widget this TQToolTip relates to.

The tip will not reappear if the cursor moves back; your maybeTip() must reinstate it each time.

If the tip does not fit inside geometry, the tip expands.


This file is part of the TQt toolkit. Copyright © 1995-2007 Trolltech. All Rights Reserved.


Copyright © 2007 TrolltechTrademarks
TQt 3.3.8