Compact toggle switch with label + optional tooltip.
| 437 | |
| 438 | |
| 439 | class _Switch(QWidget): |
| 440 | """Compact toggle switch with label + optional tooltip.""" |
| 441 | |
| 442 | toggled = Signal(bool) |
| 443 | |
| 444 | def __init__(self, text: str, initial: bool, tooltip: str = ""): |
| 445 | super().__init__() |
| 446 | layout = QHBoxLayout(self) |
| 447 | layout.setContentsMargins(0, 0, 0, 0) |
| 448 | self._checkbox = QCheckBox(text) |
| 449 | self._checkbox.setChecked(initial) |
| 450 | self._checkbox.toggled.connect(self.toggled.emit) |
| 451 | if tooltip: |
| 452 | self._checkbox.setToolTip(tooltip) |
| 453 | layout.addWidget(self._checkbox) |
| 454 | layout.addStretch(1) |
| 455 | |
| 456 | def isChecked(self) -> bool: |
| 457 | return self._checkbox.isChecked() |
| 458 | |
| 459 | def setChecked(self, value: bool) -> None: |
| 460 | self._checkbox.setChecked(value) |
| 461 | |
| 462 | |
| 463 | class MainWindow(QMainWindow): |
no outgoing calls
no test coverage detected