Web Analytics Made Easy - Statcounter
Skip to content

Class SBGUIPushButton#

ClassList > SBGUIPushButton

QPushButton subclass that can display an animated GIF overlay (e.g., a busy spinner) on top of the button's icon while a "busy" state is active. More...

  • #include <SBGUIPushButton.hpp>

Inherits the following classes: QPushButton, QPushButton

Public Functions#

Type Name
SBGUIPushButton (QWidget * parent=nullptr)
Constructs a SBGUIPushButton with an optional parent widget.
bool dimBaseIconWhileBusy () const
Returns whether the shade is drawn.
bool isBusy () const
Returns whether overlay is shown.
QPoint overlayOffset () const
Returns the overlay offset.
qreal overlayScale () const
Returns the overlay scale.
void setBusy (bool on)
Enable or disable the busy overlay.
void setDimBaseIconWhileBusy (bool on)
If true, draws a subtle shade over the base icon while busy.
bool setOverlayGif (const QString & path)
Load a GIF (from file path or Qt resource) to use as the busy overlay.
void setOverlayMovie (QMovie * movie)
Provide an already-constructed QMovie as the overlay.
void setOverlayOffset (const QPoint & px)
Optional pixel offset to nudge the overlay relative to the icon rect.
void setOverlayScale (qreal s)
Scale overlay relative to the base icon rectangle.
~SBGUIPushButton () override

Protected Functions#

Type Name
void paintEvent (QPaintEvent * e) override
Paints the standard QPushButton then, if busy, draws the animated overlay centered on the button's icon rectangle.

Detailed Description#

Usage: auto* btn = new SBGUIPushButton(parent); btn->setIcon(QIcon(":/icons/download.svg")); btn->setOverlayGif(":/spinners/spinner.gif"); btn->setBusy(true); // starts animation overlay

Notes: * The overlay scales relative to the button's iconSize(). * Optionally dims the base icon while busy to provide visual feedback. * A fallback repaint timer is used in case the QMovie doesn't emit frameChanged.

Public Functions Documentation#

function SBGUIPushButton#

Constructs a SBGUIPushButton with an optional parent widget.

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

Creates a new button instance. The button is initially not busy and has default overlay settings.

Parameters:

  • parent The parent widget for this button, or nullptr.

function dimBaseIconWhileBusy#

Returns whether the shade is drawn.

bool SBGUIPushButton::dimBaseIconWhileBusy () const


function isBusy#

Returns whether overlay is shown.

bool SBGUIPushButton::isBusy () const


function overlayOffset#

Returns the overlay offset.

QPoint SBGUIPushButton::overlayOffset () const


function overlayScale#

Returns the overlay scale.

qreal SBGUIPushButton::overlayScale () const


function setBusy#

Enable or disable the busy overlay.

void SBGUIPushButton::setBusy (
    bool on
) 

Starts/stops the movie and triggers repaints.

Parameters:

  • on true to enable the busy overlay, false to disable it.

function setDimBaseIconWhileBusy#

If true, draws a subtle shade over the base icon while busy.

void SBGUIPushButton::setDimBaseIconWhileBusy (
    bool on
) 

Enable or disable drawing a subtle shade over the base icon while busy.

Parameters:

  • on True to draw the shade, false to disable it.

function setOverlayGif#

Load a GIF (from file path or Qt resource) to use as the busy overlay.

bool SBGUIPushButton::setOverlayGif (
    const QString & path
) 

Ownership: the created QMovie is parented to this button.

Parameters:

  • path File path or qrc path to a GIF.

Returns:

true on success, false if the movie is invalid.


function setOverlayMovie#

Provide an already-constructed QMovie as the overlay.

void SBGUIPushButton::setOverlayMovie (
    QMovie * movie
) 

Provide an already‑constructed QMovie as the overlay.

Ownership is transferred to this button (parent is set to this).

Parameters:

  • movie QMovie to use (may be nullptr to clear).

function setOverlayOffset#

Optional pixel offset to nudge the overlay relative to the icon rect.

void SBGUIPushButton::setOverlayOffset (
    const QPoint & px
) 

Set an optional pixel offset to nudge the overlay relative to the icon rect.

Parameters:

  • px Pixel offset to apply.

function setOverlayScale#

Scale overlay relative to the base icon rectangle.

void SBGUIPushButton::setOverlayScale (
    qreal s
) 

1.0 = same size, 0.8 = 80%, etc. Clamped to [0.2, 2.0].

Parameters:

  • s Desired overlay scale factor.

function ~SBGUIPushButton#

SBGUIPushButton::~SBGUIPushButton () override

Protected Functions Documentation#

function paintEvent#

Paints the standard QPushButton then, if busy, draws the animated overlay centered on the button's icon rectangle.

void SBGUIPushButton::paintEvent (
    QPaintEvent * e
) override

Paint the standard QPushButton and, if busy, draw the animated overlay centered on the button's icon rectangle.

Parameters:

  • e The paint event describing the area to be repainted.