Qt 4.8
Static Public Functions | Private Functions | List of all members
QToolTip Class Reference

The QToolTip class provides tool tips (balloon help) for any widget. More...

#include <qtooltip.h>

Static Public Functions

static QFont font ()
 Returns the font used to render tooltips. More...
 
static void hideText ()
 Hides the tool tip. More...
 
static bool isVisible ()
 Returns true if this tooltip is currently shown. More...
 
static QPalette palette ()
 Returns the palette used to render tooltips. More...
 
static void setFont (const QFont &)
 Sets the font used to render tooltips. More...
 
static void setPalette (const QPalette &)
 Sets the palette used to render tooltips. More...
 
static void showText (const QPoint &pos, const QString &text, QWidget *w=0)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This is analogous to calling QToolTip::showText(pos, text, w, QRect()) More...
 
static void showText (const QPoint &pos, const QString &text, QWidget *w, const QRect &rect)
 Shows text as a tool tip, with the global position pos as the point of interest. More...
 
static QString text ()
 Returns the tooltip text, if a tooltip is visible, or an empty string if a tooltip is not visible. More...
 

Private Functions

 QToolTip ()
 

Detailed Description

The QToolTip class provides tool tips (balloon help) for any widget.

The tip is a short piece of text reminding the user of the widget's function. It is drawn immediately below the given position in a distinctive black-on-yellow color combination. The tip can be any rich text formatted string.

Rich text displayed in a tool tip is implicitly word-wrapped unless specified differently with

.

The simplest and most common way to set a widget's tool tip is by calling its QWidget::setToolTip() function.

It is also possible to show different tool tips for different regions of a widget, by using a QHelpEvent of type QEvent::ToolTip. Intercept the help event in your widget's QWidget::event() function and call QToolTip::showText() with the text you want to display. The Tooltips example illustrates this technique.

If you are calling QToolTip::hideText(), or QToolTip::showText() with an empty string, as a result of a QEvent::ToolTip-event you should also call QEvent::ignore() on the event, to signal that you don't want to start any tooltip specific modes.

Note that, if you want to show tooltips in an item view, the model/view architecture provides functionality to set an item's tool tip; e.g., the QTableWidgetItem::setToolTip() function. However, if you want to provide custom tool tips in an item view, you must intercept the help event in the QAbstractItemView::viewportEvent() function and handle it yourself.

The default tool tip color and font can be customized with setPalette() and setFont(). When a tooltip is currently on display, isVisible() returns true and text() the currently visible text.

Note
Tool tips use the inactive color group of QPalette, because tool tips are not active windows.
See also
QWidget::toolTip, QAction::toolTip, {Tool Tips Example}

Definition at line 55 of file qtooltip.h.

Constructors and Destructors

◆ QToolTip()

QToolTip::QToolTip ( )
private

Functions

◆ font()

QFont QToolTip::font ( )
static

Returns the font used to render tooltips.

Since
4.2

Definition at line 570 of file qtooltip.cpp.

571 {
572  return QApplication::font("QTipLabel");
573 }
static QFont font()
Returns the default application font.

◆ hideText()

void QToolTip::hideText ( )
inlinestatic

Hides the tool tip.

Since
4.2

This is the same as calling showText() with an empty string.

See also
showText()

Definition at line 61 of file qtooltip.h.

Referenced by QMDIControl::event(), and QGraphicsScenePrivate::leaveScene().

61 { showText(QPoint(), QString()); }
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
static void showText(const QPoint &pos, const QString &text, QWidget *w=0)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qtooltip.cpp:497

◆ isVisible()

bool QToolTip::isVisible ( )
static

Returns true if this tooltip is currently shown.

Since
4.4
See also
showText()

Definition at line 527 of file qtooltip.cpp.

528 {
530 }
static QTipLabel * instance
Definition: qtooltip.cpp:127
static bool isVisible()
Returns true if this tooltip is currently shown.
Definition: qtooltip.cpp:527

◆ palette()

QPalette QToolTip::palette ( )
static

Returns the palette used to render tooltips.

Note
Tool tips use the inactive color group of QPalette, because tool tips are not active windows.

Definition at line 557 of file qtooltip.cpp.

Referenced by QRenderRule::QRenderRule(), and QTipLabel::QTipLabel().

558 {
559  return *tooltip_palette();
560 }

◆ setFont()

void QToolTip::setFont ( const QFont font)
static

Sets the font used to render tooltips.

Since
4.2

Definition at line 601 of file qtooltip.cpp.

602 {
603  QApplication::setFont(font, "QTipLabel");
604 }
static void setFont(const QFont &, const char *className=0)
Changes the default application font to font.

◆ setPalette()

void QToolTip::setPalette ( const QPalette palette)
static

Sets the palette used to render tooltips.

Since
4.2
Note
Tool tips use the inactive color group of QPalette, because tool tips are not active windows.

Definition at line 586 of file qtooltip.cpp.

Referenced by qt_set_windows_color_resources().

587 {
588  *tooltip_palette() = palette;
591 }
static QPalette palette()
Returns the palette used to render tooltips.
Definition: qtooltip.cpp:557
static QTipLabel * instance
Definition: qtooltip.cpp:127
void setPalette(const QPalette &)
Use the single-argument overload instead.
Definition: qwidget.cpp:4858

◆ showText() [1/2]

void QToolTip::showText ( const QPoint pos,
const QString text,
QWidget w = 0 
)
static

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This is analogous to calling QToolTip::showText(pos, text, w, QRect())

Definition at line 497 of file qtooltip.cpp.

Referenced by QMDIControl::event(), QTabBar::event(), QWidget::event(), QScriptToolTipJob::handleResponse(), QAbstractItemDelegate::helpEvent(), QGraphicsScene::helpEvent(), QTextControlPrivate::showToolTip(), showToolTip(), and QHeaderView::viewportEvent().

498 {
499  QToolTip::showText(pos, text, w, QRect());
500 }
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
static void showText(const QPoint &pos, const QString &text, QWidget *w=0)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qtooltip.cpp:497

◆ showText() [2/2]

void QToolTip::showText ( const QPoint pos,
const QString text,
QWidget w,
const QRect rect 
)
static

Shows text as a tool tip, with the global position pos as the point of interest.

The tool tip will be shown with a platform specific offset from this point of interest.

If you specify a non-empty rect the tip will be hidden as soon as you move your cursor out of this area.

The rect is in the coordinates of the widget you specify with w. If the rect is not empty you must specify a widget. Otherwise this argument can be 0 but it is used to determine the appropriate screen on multi-head systems.

If text is empty the tool tip is hidden. If the text is the same as the currently shown tooltip, the tip will not move. You can force moving by first hiding the tip with an empty text, and then showing the new tip at the new position.

Definition at line 443 of file qtooltip.cpp.

444 {
445  if (QTipLabel::instance && QTipLabel::instance->isVisible()){ // a tip does already exist
446  if (text.isEmpty()){ // empty text means hide current tip
448  return;
449  }
450  else if (!QTipLabel::instance->fadingOut){
451  // If the tip has changed, reuse the one
452  // that is showing (removes flickering)
453  QPoint localPos = pos;
454  if (w)
455  localPos = w->mapFromGlobal(pos);
456  if (QTipLabel::instance->tipChanged(localPos, text, w)){
459  QTipLabel::instance->placeTip(pos, w);
460  }
461  return;
462  }
463  }
464 
465  if (!text.isEmpty()){ // no tip can be reused, create new tip:
466 #ifndef Q_WS_WIN
467  new QTipLabel(text, w); // sets QTipLabel::instance to itself
468 #else
469  // On windows, we can't use the widget as parent otherwise the window will be
470  // raised when the tooltip will be shown
471  new QTipLabel(text, QApplication::desktop()->screen(QTipLabel::getTipScreen(pos, w)));
472 #endif
474  QTipLabel::instance->placeTip(pos, w);
475  QTipLabel::instance->setObjectName(QLatin1String("qtooltip_label"));
476 
477 
478 #if !defined(QT_NO_EFFECTS) && !defined(Q_WS_MAC)
483  else
485 #else
487 #endif
488  }
489 }
void setTipRect(QWidget *w, const QRect &r)
Definition: qtooltip.cpp:274
static QTipLabel * instance
Definition: qtooltip.cpp:127
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
void setObjectName(const QString &name)
Definition: qobject.cpp:1112
void qScrollEffect(QWidget *w, QEffects::DirFlags orient, int time)
Scroll widget w in time ms.
Definition: qeffects.cpp:562
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
void show()
Shows the widget and its child widgets.
static QDesktopWidget * desktop()
Returns the desktop widget (also called the root window).
static bool isEffectEnabled(Qt::UIEffect)
Returns true if effect is enabled; otherwise returns false.
void hideTip()
Definition: qtooltip.cpp:262
void reuseTip(const QString &text)
Definition: qtooltip.cpp:202
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
QPoint mapFromGlobal(const QPoint &) const
Translates the global screen coordinate pos to widget coordinates.
static bool isVisible()
Returns true if this tooltip is currently shown.
Definition: qtooltip.cpp:527
void qFadeEffect(QWidget *w, int time)
Fade in widget w in time ms.
Definition: qeffects.cpp:584
static int getTipScreen(const QPoint &pos, QWidget *w)
Definition: qtooltip.cpp:345
void placeTip(const QPoint &pos, QWidget *w)
Definition: qtooltip.cpp:353

◆ text()

QString QToolTip::text ( )
static

Returns the tooltip text, if a tooltip is visible, or an empty string if a tooltip is not visible.

Since
4.4

Definition at line 541 of file qtooltip.cpp.

542 {
544  return QTipLabel::instance->text();
545  return QString();
546 }
static QTipLabel * instance
Definition: qtooltip.cpp:127
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString text() const

The documentation for this class was generated from the following files: