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.
 

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 200 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 133 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 228 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 191 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 178 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 204 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 185 of file gQtButtonsWidget.cc.


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