gqtbuttonswidget
Loading...
Searching...
No Matches
GQTToggleButtonWidget Class Reference

Group of toggleable push buttons with a tracked "last pressed" index. More...

#include <gQtButtonsWidget.h>

Signals

void buttonPressedIndexChanged (int index)
 Emitted whenever the last pressed button index changes.
 

Public Member Functions

 GQTToggleButtonWidget (int buttonWidth, int buttonHeight, int borderRadius, const std::vector< std::string > &titles, bool vertical=true, QWidget *parent=nullptr)
 Constructs a GQTToggleButtonWidget.
 
int buttonPressed () const
 Returns the last pressed button index.
 
bool lastButtonState () const
 Returns the checked state of the last pressed button.
 
void toggleButton (int index)
 Toggle the checked state of a button.
 
bool buttonStatus (int index) const
 Returns the checked state for a specific button.
 
void reset_buttons ()
 Uncheck all buttons.
 
void setSvgButtonIcon (int index, const QString &svgResourcePath, const QSize &iconSize=QSize())
 Assign an SVG resource to a button so it re-renders on every palette/theme change.
 

Protected Member Functions

void changeEvent (QEvent *event) override
 
void showEvent (QShowEvent *event) override
 

Detailed Description

This widget constructs one checkable QPushButton per title and places them into a layout selected by vertical. When a button is clicked, the widget stores the pressed index and emits buttonPressedIndexChanged().

Note
This widget does not enforce mutual exclusivity; multiple buttons may be checked simultaneously. The "pressed index" refers to the last clicked button, not the only active button.

Definition at line 218 of file gQtButtonsWidget.h.

Constructor & Destructor Documentation

◆ GQTToggleButtonWidget()

GQTToggleButtonWidget::GQTToggleButtonWidget ( int buttonWidth,
int buttonHeight,
int borderRadius,
const std::vector< std::string > & titles,
bool vertical = true,
QWidget * parent = nullptr )
explicit
Parameters
buttonWidthFixed width of each button in pixels.
buttonHeightFixed height of each button in pixels.
borderRadiusBorder radius (in pixels) used to round button corners.
titlesTitles (labels) for the buttons.
verticalIf true, buttons are arranged in a column; otherwise in a row.
parentParent widget (Qt ownership). Default is nullptr.

Definition at line 170 of file gQtButtonsWidget.cc.

Member Function Documentation

◆ buttonPressed()

int GQTToggleButtonWidget::buttonPressed ( ) const
inline

If no button has been pressed yet, the value is -1.

Returns
Last pressed button index.

Definition at line 246 of file gQtButtonsWidget.h.

◆ buttonPressedIndexChanged

void GQTToggleButtonWidget::buttonPressedIndexChanged ( int index)
signal
Parameters
indexThe new pressed button index.

◆ buttonStatus()

bool GQTToggleButtonWidget::buttonStatus ( int index) const
Parameters
indexIndex of the button to query. Out-of-range values return false.
Returns
true if the button is checked; otherwise false.

Definition at line 224 of file gQtButtonsWidget.cc.

◆ changeEvent()

void GQTToggleButtonWidget::changeEvent ( QEvent * event)
overrideprotected

Definition at line 286 of file gQtButtonsWidget.cc.

◆ lastButtonState()

bool GQTToggleButtonWidget::lastButtonState ( ) const

If no button has been pressed yet, or if the stored index is out of range, returns false.

Returns
true if the last pressed button is currently checked; otherwise false.

Definition at line 211 of file gQtButtonsWidget.cc.

◆ reset_buttons()

void GQTToggleButtonWidget::reset_buttons ( )

This resets only the check state of all buttons. It does not emit buttonPressedIndexChanged() and it does not modify buttonPressedIndex.

Definition at line 237 of file gQtButtonsWidget.cc.

◆ setSvgButtonIcon()

void GQTToggleButtonWidget::setSvgButtonIcon ( int index,
const QString & svgResourcePath,
const QSize & iconSize = QSize() )

The SVG must use currentColor for all strokes and fills; the widget substitutes the active palette's WindowText color each time the palette or style changes, keeping icons readable in both light and dark mode.

Parameters
indexIndex of the button to update. Out-of-range values are ignored.
svgResourcePathQt resource path, e.g. ":/images/hidden_lines.svg".
iconSizeRendered size. Defaults to the button's fixed size minus 6 px padding.

Definition at line 244 of file gQtButtonsWidget.cc.

◆ showEvent()

void GQTToggleButtonWidget::showEvent ( QShowEvent * event)
overrideprotected

Definition at line 295 of file gQtButtonsWidget.cc.

◆ toggleButton()

void GQTToggleButtonWidget::toggleButton ( int index)
Parameters
indexIndex of the button to toggle. Out-of-range values are ignored.

Definition at line 218 of file gQtButtonsWidget.cc.


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