Web Analytics Made Easy - Statcounter
Skip to content

Class SBGUIToolTip#

ClassList > SBGUIToolTip

The SBGUIToolTip class provides a custom tooltip widget with rich-text and clickable link support.

  • #include <SBGUIToolTip.hpp>

Inherits the following classes: QWidget

Public Types#

Type Name
typedef std::function< void(const QString &href)> LinkHandler
Type for a global link handler (receives the full href, e.g. "action://UUID" or "https://...").
typedef std::function< void(const QString &href)> LinkHoverHandler

Public Functions#

Type Name
SBGUIToolTip (QWidget * parent=nullptr)
Constructs a SBGUIToolTip widget with an optional parent.
QLabel * getLabel () const
Access internal label (useful if you also show manual tooltips).
void setHtml (QString htmlOrPlain)
Sets the tooltip text using either HTML or plain text.
void showAt (const QPoint & globalAnchor)
Shows the tooltip near a global screen position, adjusting its placement to stay within screen bounds.

Public Static Functions#

Type Name
void installFor (QWidget * target)
Installs a tooltip filter on a specific widget, enabling custom tooltip handling for that widget.
void installFor (QApplication * app)
Installs a global tooltip filter on the application, enabling custom tooltip handling across the entire application.
void setGlobalLinkHandler (LinkHandler handler)
Sets a global link handler used by tooltips installed via installFor(&app).
void setGlobalLinkHoverHandler (LinkHoverHandler handler)
Sets a global link hover handler to be called when the mouse hovers over a link in a tooltip.

Protected Functions#

Type Name
void enterEvent (QEnterEvent * e) override
Handles the event when the mouse enters the tooltip widget.
bool eventFilter (QObject * obj, QEvent * event) override
Filters events for the tooltip widget to manage visibility and cursor handling.
void leaveEvent (QEvent * e) override
Handles the event when the mouse leaves the tooltip widget.
void paintEvent (QPaintEvent * e) override
Paints the tooltip widget using the style's widget primitive.

Public Types Documentation#

typedef LinkHandler#

Type for a global link handler (receives the full href, e.g. "action://UUID" or "https://...").

using SBGUIToolTip::LinkHandler =  std::function<void(const QString& href)>;


typedef LinkHoverHandler#

using SBGUIToolTip::LinkHoverHandler =  std::function<void(const QString& href)>;

Public Functions Documentation#

function SBGUIToolTip#

Constructs a SBGUIToolTip widget with an optional parent.

explicit SBGUIToolTip::SBGUIToolTip (
    QWidget * parent=nullptr
) 

Parameters:

  • parent The parent widget for the tooltip. If nullptr, the tooltip has no parent.

function getLabel#

Access internal label (useful if you also show manual tooltips).

QLabel * SBGUIToolTip::getLabel () const

Returns the internal QLabel used to display the tooltip content.

Returns:

Pointer to the QLabel instance.


function setHtml#

Sets the tooltip text using either HTML or plain text.

void SBGUIToolTip::setHtml (
    QString htmlOrPlain
) 

If plain text is provided, it will be escaped and wrapped in a <span> element.

Parameters:

  • htmlOrPlain The HTML or plain text to display in the tooltip.

function showAt#

Shows the tooltip near a global screen position, adjusting its placement to stay within screen bounds.

void SBGUIToolTip::showAt (
    const QPoint & globalAnchor
) 

Parameters:

  • globalAnchor The global screen position used as the anchor point for the tooltip.

Public Static Functions Documentation#

function installFor [1/2]#

Installs a tooltip filter on a specific widget, enabling custom tooltip handling for that widget.

static void SBGUIToolTip::installFor (
    QWidget * target
) 

Parameters:

  • target The widget on which to install the tooltip filter.

function installFor [2/2]#

Installs a global tooltip filter on the application, enabling custom tooltip handling across the entire application.

static void SBGUIToolTip::installFor (
    QApplication * app
) 

Parameters:

  • app Pointer to the QApplication instance.

function setGlobalLinkHandler#

Sets a global link handler used by tooltips installed via installFor(&app).

static void SBGUIToolTip::setGlobalLinkHandler (
    LinkHandler handler
) 

Sets a global link handler used for link activation in tooltips installed via installFor(&app).

If set, every link click in any tooltip calls this callback. You can route "action://..." here. If unset, http(s) links will open with QDesktopServices.

Parameters:

  • handler The callback to be invoked with the href of the clicked link.

function setGlobalLinkHoverHandler#

Sets a global link hover handler to be called when the mouse hovers over a link in a tooltip.

static void SBGUIToolTip::setGlobalLinkHoverHandler (
    LinkHoverHandler handler
) 

Parameters:

  • h The callback receiving the href of the hovered link.

Protected Functions Documentation#

function enterEvent#

Handles the event when the mouse enters the tooltip widget.

void SBGUIToolTip::enterEvent (
    QEnterEvent * e
) override

Stops the inactivity timer to keep the tooltip visible.

Parameters:

  • e Enter event.

function eventFilter#

Filters events for the tooltip widget to manage visibility and cursor handling.

bool SBGUIToolTip::eventFilter (
    QObject * obj,
    QEvent * event
) override

Handles application/window deactivation and mouse button presses outside the tooltip to hide it.

Parameters:

  • obj The object that received the event.
  • event The event to filter.

Returns:

true if the event is filtered and further processing should stop; otherwise false.


function leaveEvent#

Handles the event when the mouse leaves the tooltip widget.

void SBGUIToolTip::leaveEvent (
    QEvent * e
) override

Restores the cursor and may hide the tooltip after a short delay if the mouse does not re-enter.

Parameters:

  • e Leave event.

function paintEvent#

Paints the tooltip widget using the style's widget primitive.

void SBGUIToolTip::paintEvent (
    QPaintEvent * e
) override

Parameters:

  • e Paint event (unused).