Replace a plain QCheckBox with a labelled ToggleSwitch (label on the LEFT, switch on the right). The checkbox is kept hidden+alive so plugin data and the connectWidgetSignals event callback keep flowing through it; the toggle just drives it. No-op for tristate / textless / composite-internal / already adapted checkboxes.
| 417 | // just drives it. No-op for tristate / textless / composite-internal / already |
| 418 | // adapted checkboxes. |
| 419 | static bool tryAdaptCheckBox(QCheckBox* checkbox) { |
| 420 | if (checkbox == nullptr || pairedToggleSwitch(checkbox) != nullptr) { |
| 421 | return false; |
| 422 | } |
| 423 | if (checkbox->isTristate() || checkbox->text().isEmpty()) { |
| 424 | return false; |
| 425 | } |
| 426 | QWidget* parent = checkbox->parentWidget(); |
| 427 | if (parent == nullptr || parent->layout() == nullptr || isInsideHostComposite(checkbox)) { |
| 428 | return false; |
| 429 | } |
| 430 | |
| 431 | auto* toggle = new ToggleSwitch(parent); |
| 432 | toggle->setText(checkbox->text()); |
| 433 | toggle->setLabelSide(ToggleSwitch::LabelSide::Left); |
| 434 | toggle->setToolTip(checkbox->toolTip()); |
| 435 | toggle->setEnabled(checkbox->isEnabled()); |
| 436 | toggle->setChecked(checkbox->isChecked(), /*animate=*/false); |
| 437 | |
| 438 | if (!replaceWidgetInLayout(parent, checkbox, toggle)) { |
| 439 | delete toggle; |
| 440 | return false; |
| 441 | } |
| 442 | checkbox->setProperty(kToggleSwitchProperty, QVariant::fromValue<QObject*>(toggle)); |
| 443 | checkbox->setProperty(kToggleDesiredVisibleProperty, !checkbox->isHidden()); |
| 444 | toggle->setProperty(kToggleCheckBoxProperty, QVariant::fromValue<QObject*>(checkbox)); |
| 445 | checkbox->hide(); |
| 446 | |
| 447 | const QPointer<QCheckBox> cb_ptr(checkbox); |
| 448 | QObject::connect(toggle, &ToggleSwitch::toggled, toggle, [cb_ptr](bool checked) { |
| 449 | if (cb_ptr != nullptr) { |
| 450 | cb_ptr->setChecked(checked); |
| 451 | } |
| 452 | }); |
| 453 | QObject::connect(checkbox, &QCheckBox::toggled, toggle, [checkbox, toggle](bool checked) { |
| 454 | const QSignalBlocker blocker(toggle); |
| 455 | toggle->setChecked(checked, /*animate=*/false); |
| 456 | checkbox->hide(); |
| 457 | }); |
| 458 | return true; |
| 459 | } |
| 460 | |
| 461 | // --- QTableView interior-only cell grid -------------------------------------- |
| 462 |
no test coverage detected