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

Icon-based button strip widget implemented using a QListWidget. More...

#include <gQtButtonsWidget.h>

Public Member Functions

 GQTButtonsWidget (double h, double v, const std::vector< std::string > &bicons, bool vertical=true, QWidget *parent=nullptr)
 Constructs a GQTButtonsWidget.
 
 ~GQTButtonsWidget () override=default
 
int button_pressed () const
 Returns the index of the currently selected (pressed) button.
 
void press_button (int i)
 Programmatically press a button.
 
void reset_buttons ()
 Reset all buttons to the "normal" icon state.
 

Data Fields

QListWidget * buttonsWidget
 Underlying QListWidget used to render the icons.
 

Detailed Description

GQTButtonsWidget uses a QListWidget in QListView::IconMode as the rendering backend. Each entry is a QListWidgetItem whose icon is updated to reflect interaction.

Typical behavior:

  • When a user presses an item, all items are reset to the "normal" icon (state 1) and the pressed item is set to the "pressed" icon (state 2).
  • press_button() allows pressing a button programmatically.
  • reset_buttons() restores all icons to the "normal" state.
Note
This widget is intended for use in the Qt GUI thread.

Definition at line 93 of file gQtButtonsWidget.h.

Constructor & Destructor Documentation

◆ GQTButtonsWidget()

GQTButtonsWidget::GQTButtonsWidget ( double h,
double v,
const std::vector< std::string > & bicons,
bool vertical = true,
QWidget * parent = nullptr )
explicit

The constructor:

  • creates one internal ButtonInfo per entry in bicons
  • instantiates and configures a QListWidget in icon mode
  • sets icon size based on h and v
  • lays out the list vertically or horizontally based on vertical
Parameters
hIcon width in pixels (used for QListWidget::setIconSize()).
vIcon height in pixels (used for QListWidget::setIconSize()).
biconsVector of base icon names used to locate icons.
verticalIf true, buttons are arranged in a column; otherwise in a row.
parentParent widget (Qt ownership). Default is nullptr.

Definition at line 44 of file gQtButtonsWidget.cc.

◆ ~GQTButtonsWidget()

GQTButtonsWidget::~GQTButtonsWidget ( )
overridedefault

Member Function Documentation

◆ button_pressed()

int GQTButtonsWidget::button_pressed ( ) const
inline

This returns the current row in the underlying QListWidget. If no item is selected, Qt typically reports -1.

Returns
Index of the current row in buttonsWidget.

Definition at line 142 of file gQtButtonsWidget.h.

◆ press_button()

void GQTButtonsWidget::press_button ( int i)

This sets the current row and updates the pressed button's icon to the "pressed" state (state 2). It does not automatically reset other icons; if you need a clean state first, call reset_buttons().

Parameters
iIndex of the button to press. Out-of-range values are ignored.

Definition at line 100 of file gQtButtonsWidget.cc.

◆ reset_buttons()

void GQTButtonsWidget::reset_buttons ( )

This updates every stored QListWidgetItem icon to state 1. It does not change the current selection row.

Definition at line 118 of file gQtButtonsWidget.cc.

Field Documentation

◆ buttonsWidget

QListWidget* GQTButtonsWidget::buttonsWidget

Exposed for integration (e.g. embedding in larger GUIs, applying additional policies, connecting to more signals).

Warning
The widget is parented to this and must not be deleted externally.

Definition at line 131 of file gQtButtonsWidget.h.


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