gqtbuttonswidget
Loading...
Searching...
No Matches
gQtButtonsWidget.h
Go to the documentation of this file.
1#pragma once
2
3// C++
4#include <string>
5#include <vector>
6
7// qt
8#include <QWidget>
9#include <QListWidget>
10#include <QPushButton>
11#include <QVector>
12#include <QIcon>
13
33{
40 explicit ButtonInfo(const std::string& icon);
41
51 QListWidgetItem* thisButton;
52
70 QIcon iconForState(int state) const;
71
72private:
73 std::string buttonName;
74};
75
93class GQTButtonsWidget : public QWidget
94{
95 Q_OBJECT
96
97public:
114 explicit GQTButtonsWidget(double h, double v,
115 const std::vector<std::string>& bicons,
116 bool vertical = true,
117 QWidget* parent = nullptr);
118
119 ~GQTButtonsWidget() override = default;
120
131 QListWidget* buttonsWidget;
132
142 int button_pressed() const { return buttonsWidget->currentRow(); }
143
153 void press_button(int i);
154
162 void reset_buttons();
163
164private:
171 std::vector<ButtonInfo*> buttons;
172
173private slots:
184 void buttonWasPressed(QListWidgetItem* item);
185};
186
200class GQTToggleButtonWidget : public QWidget
201{
202 Q_OBJECT
203
204public:
215 explicit GQTToggleButtonWidget(int buttonWidth, int buttonHeight, int borderRadius,
216 const std::vector<std::string>& titles,
217 bool vertical = true,
218 QWidget* parent = nullptr);
219
228 int buttonPressed() const { return buttonPressedIndex; }
229
238 bool lastButtonState() const;
239
245 void toggleButton(int index);
246
253 bool buttonStatus(int index) const;
254
262 void reset_buttons();
263
264signals:
271
272private:
273 int buttonPressedIndex;
274 QVector<QPushButton*> buttons;
275
276private slots:
282 void setButtonPressed(int index);
283};
Icon-based button strip widget implemented using a QListWidget.
void reset_buttons()
Reset all buttons to the "normal" icon state.
QListWidget * buttonsWidget
Underlying QListWidget used to render the icons.
void press_button(int i)
Programmatically press a button.
GQTButtonsWidget(double h, double v, const std::vector< std::string > &bicons, bool vertical=true, QWidget *parent=nullptr)
Constructs a GQTButtonsWidget.
int button_pressed() const
Returns the index of the currently selected (pressed) button.
~GQTButtonsWidget() override=default
Group of toggleable push buttons with a tracked "last pressed" index.
void toggleButton(int index)
Toggle the checked state of a button.
GQTToggleButtonWidget(int buttonWidth, int buttonHeight, int borderRadius, const std::vector< std::string > &titles, bool vertical=true, QWidget *parent=nullptr)
Constructs a GQTToggleButtonWidget.
void reset_buttons()
Uncheck all buttons.
int buttonPressed() const
Returns the last pressed button index.
void buttonPressedIndexChanged(int index)
Emitted whenever the last pressed button index changes.
bool buttonStatus(int index) const
Returns the checked state for a specific button.
bool lastButtonState() const
Returns the checked state of the last pressed button.
Logical description of one icon-button entry used by GQTButtonsWidget.
QListWidgetItem * thisButton
The UI item representing this logical button.
ButtonInfo(const std::string &icon)
Constructs a ButtonInfo for a given base icon name.
QIcon iconForState(int state) const
Returns the icon for a given interaction state.