21 thisButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
26 std::string filename = buttonName +
"_" + std::to_string(state) +
".svg";
29 QFileInfo fileInfo(QString::fromStdString(filename));
30 if (fileInfo.exists() && fileInfo.isFile()) {
31 return QIcon(QString::fromStdString(filename));
45 const std::vector<std::string>& bicons,
46 bool vertical, QWidget* parent)
48 constexpr int distanceToMargin = 12;
51 for (
const auto& b : bicons) {
58 buttonsWidget->setIconSize(QSize(
static_cast<int>(h),
static_cast<int>(v)));
62 "background-color: transparent; "
63 "QListWidget::item:selected { background: transparent; border: none; }");
66 for (
auto& b : buttons) {
72 this, &GQTButtonsWidget::buttonWasPressed);
75 QBoxLayout* layout = vertical
76 ?
static_cast<QBoxLayout*
>(
new QVBoxLayout(
this))
77 :
static_cast<QBoxLayout*
>(
new QHBoxLayout(
this));
78 layout->setContentsMargins(0, 0, 0, 0);
83 double hsize = (h + distanceToMargin) * (buttons.size());
84 double vsize = v + distanceToMargin;
86 hsize = h + distanceToMargin;
87 vsize = (v + distanceToMargin) * (buttons.size());
89 buttonsWidget->setFixedSize(
static_cast<int>(hsize),
static_cast<int>(vsize));
94 "QListWidget { background-color: transparent; }"
95 "QListWidget::item { background: transparent; border: none; }"
96 "QListWidget::item:selected { background: transparent; border: none; outline: none; }"
103 if (i >= 0 && i <
static_cast<int>(buttons.size()))
104 buttonsWidget->item(i)->setIcon(buttons[i]->iconForState(2));
107void GQTButtonsWidget::buttonWasPressed(QListWidgetItem* item) {
110 buttonsWidget->item(i)->setIcon(buttons[i]->iconForState(1));
115 item->setIcon(buttons[index]->iconForState(2));
120 for (
auto& b : buttons) {
121 b->thisButton->setIcon(b->iconForState(1));
134 const std::vector<std::string>& titles,
135 bool vertical, QWidget* parent)
137 buttonPressedIndex(-1) {
138 QBoxLayout* layout = vertical
139 ?
static_cast<QBoxLayout*
>(
new QVBoxLayout(
this))
140 :
static_cast<QBoxLayout*
>(
new QHBoxLayout(
this));
143 QStringList buttonStrings;
144 for (
const auto& title : titles) {
145 buttonStrings.append(QString::fromStdString(title));
149 for (
int i = 0; i < buttonStrings.size(); ++i) {
150 QPushButton* button =
new QPushButton(buttonStrings[i],
this);
151 button->setCheckable(
true);
152 button->setFixedSize(buttonWidth, buttonHeight);
155 button->setStyleSheet(QString(
157 " border-radius: %1px;"
158 " border: 2px solid black;"
159 " background-color: rgba(255, 0, 0, 150);"
160 " font-weight: bold;"
162 "QPushButton:checked {"
163 " background-color: rgba(0, 255, 0, 150);"
165 ).arg(borderRadius));
167 layout->addWidget(button);
168 buttons.push_back(button);
171 connect(button, &QPushButton::clicked,
this, [
this, i]() {
172 this->setButtonPressed(i);
180 if (buttonPressedIndex >= 0 && buttonPressedIndex < buttons.size())
181 return buttons[buttonPressedIndex]->isChecked();
187 if (index >= 0 && index < buttons.size())
188 buttons[index]->toggle();
193 if (index >= 0 && index < buttons.size())
194 return buttons[index]->isChecked();
198void GQTToggleButtonWidget::setButtonPressed(
int index) {
200 buttonPressedIndex = index;
206 for (
auto& b : buttons) {
207 b->setChecked(
false);