- Qt 6.12
- Qt Quick Controls
- QML Types
- ToolTip
- Qt 6.12.0 Reference Documentation

# ToolTip QML Type

Provides tool tips for any control. More...

Import Statement: | `import QtQuick.Controls`
Inherits: | Popup

- List of all members, including inherited members

## Properties

- delay : int
- text : string
- timeout : int

## Attached Properties

- delay : int
- policy : enumeration `(since 6.12)`
- text : string
- timeout : int
- toolTip : ToolTip
- visible : bool

## Methods

- void hide() `(since QtQuick.Controls 2.5 (Qt 5.12))`
- void show(string text, int timeout) `(since QtQuick.Controls 2.5 (Qt 5.12))`

## Attached Methods

- void hide()
- void show(string text, int timeout)

## Detailed Description

A tool tip is a short piece of text that informs the user of a control's function. It is typically placed above or below the parent control. The tip text can be any rich text formatted string.

### Attached Tool Tips

The most straight-forward way to setup tool tips for controls is to specify text and visibility via attached properties. The following example illustrates this approach:

     Button {
         text: qsTr("Save")

         ToolTip.visible: down
         ToolTip.text: qsTr("Save the active project")
     }

Under normal circumstances, there is only one tool tip visible at a time. In order to save resources, all items that use the ToolTip attached property share the same visual tool tip label instance. Even though the visuals are shared, `text`, `timeout` and `delay` are stored individually for each item that uses the respective attached property. However, multiple items cannot make the shared tool tip visible at the same time. The shared tool tip is only shown for the last item that made it visible. The position of the shared tool tip is determined by the framework.

Note: to customize the attached ToolTip, it must be provided as part of your own style. To do a one-off customization of a `ToolTip`, see Custom Tool Tips.

### Delay and Timeout

Tool tips are typically transient in a sense that they are shown as a result of a certain external event or user interaction, and they usually hide after a certain timeout. It is possible to control the delay when a tool tip is shown, and the timeout when it is hidden. This makes it possible to implement varying strategies for showing and hiding tool tips.

For example, on touch screens, it is a common pattern to show a tool tip as a result of pressing and holding down a button. The following example demonstrates how to delay showing a tool tip until the press-and-hold interval is reached. In this example, the tool tip hides as soon as the button is released.

     Button {
         text: qsTr("Button")

         ToolTip.visible: pressed
         ToolTip.delay: Application.styleHints.mousePressAndHoldInterval
         ToolTip.text: qsTr("This tool tip is shown after pressing and holding the button down.")
     }

With pointer devices, however, it might be desired to show a tool tip as a result of hovering a button for a while. The following example presents how to show a tool tip after hovering a button for a second, and hide it after a timeout of five seconds.

     Button {
         text: qsTr("Button")
         hoverEnabled: true

         ToolTip.delay: 1000
         ToolTip.timeout: 5000
         ToolTip.visible: hovered
         ToolTip.text: qsTr("This tool tip is shown after hovering the button for a second.")
     }

### Custom Tool Tips

Should one need more fine-grained control over the tool tip position, or multiple simultaneous tool tip instances are needed, it is also possible to create local tool tip instances. This way, it is possible to customize the tool tip, and the whole Popup API is available. The following example presents a tool tip that presents the value of a slider when the handle is dragged.

     Slider {
         id: slider
         value: 0.5

         ToolTip {
             parent: slider.handle
             visible: slider.pressed
             text: slider.value.toFixed(1)
         }
     }

See also Customizing ToolTip, Popup Controls, and closePolicy.

## Property Documentation

### delay : int

This property holds the delay (milliseconds) after which the tool tip is shown. A tooltip with a negative delay is shown immediately. The default value is `0`.

See also Delay and Timeout.

### text : string

This property holds the text shown on the tool tip.

### timeout : int

This property holds the timeout (milliseconds) after which the tool tip is hidden. A tooltip with a negative timeout does not hide automatically. The default value is `-1`.

See also Delay and Timeout.

## Attached Property Documentation

### ToolTip.delay : int `[attached]`

This attached property holds the delay (milliseconds) of the shared tool tip. The property can be attached to any item.

The default value is `0` if policy is `ToolTip.Manual`, otherwise it is QStyleHints::toolTipWakeUpDelay().

See also Attached Tool Tips and Delay and Timeout.

### ToolTip.policy : enumeration `[attached, since 6.12]`

This attached property controls whether the visibility of the shared tool tip instance is handled automatically. It only has an effect for items on which `ToolTip.visible` has not been set. Only items that set `ToolTip.text` will be made visible. It only has an effect for the following items and their derived types: Control, TextArea and TextField. All other types require visible to be manually set.

It also determines the default values for the delay and timeout properties of the shared tool tip instance (regardless of whether `ToolTip.visible` or `ToolTip.text` have been set).

This property is propagated to attached ToolTip children.

Available values:

Constant | Description
--- | ---
`ToolTip.Automatic` | The shared tool tip will be shown when the attachee is hovered or long-pressed (if triggered by touch and the attachee is an AbstractButton or one of its derived types). If the visible property has been explicitly set, or the text property has not been set, this value has no effect, and the behavior will be equivalent to `ToolTip.Manual`.

The shared tool tip will also default to platform-specific values for its delay and timeout properties.

Constant | Description
--- | ---
`ToolTip.Manual` | The shared tool tip will not be shown automatically, and the developer is responsible for setting the visible property.

The shared tool tip will not default to platform-specific values for its delay and timeout properties.

The default value is `ToolTip.Automatic`.

The property provides a way to opt-out of the default values for shared tool tips introduced in Qt 6.12. This is particularly relevant for legacy code that doesn't explicitly set the visible property before an item is interacted with. For applications that declaratively set the visible property and find the new default values for delay and timeout acceptable, `policy` is not needed.

This property was introduced in Qt 6.12.

See also Attached Tool Tips.

### ToolTip.text : string `[attached]`

This attached property holds the text of the shared tool tip. The property can be attached to any item.

See also Attached Tool Tips.

### ToolTip.timeout : int `[attached]`

This attached property holds the timeout (milliseconds) of the shared tool tip. The property can be attached to any item.

The default value is based on the length of the text, and will always be at least 10 seconds long.

See also Attached Tool Tips and Delay and Timeout.

### ToolTip.toolTip : ToolTip `[attached]`

This attached property holds the shared tool tip instance. The property can be attached to any item.

See also Attached Tool Tips.

### ToolTip.visible : bool `[attached]`

This attached property holds whether the shared tool tip is visible. The property can be attached to any item.

See also Attached Tool Tips.

## Method Documentation

### `[since QtQuick.Controls 2.5 (Qt 5.12)]` void hide()

This method hides the tooltip.

This method was introduced in QtQuick.Controls 2.5 (Qt 5.12).

### `[since QtQuick.Controls 2.5 (Qt 5.12)]` void show(string text, int timeout)

This method shows the text as a tooltip, which times out in timeout (milliseconds).

This method was introduced in QtQuick.Controls 2.5 (Qt 5.12).

## Attached Method Documentation

### `[attached]` void hide()

This attached method hides the shared tooltip. The method can be attached to any item.

See also Attached Tool Tips.

### `[attached]` void show(string text, int timeout = -1)

This attached method shows the shared tooltip with text and timeout (milliseconds). The method can be attached to any item.

See also Attached Tool Tips.