docs: document QToggleSwitch (#286)

* wip

* add toggleswitch

* style: [pre-commit.ci] auto fixes [...]

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Talley Lambert
2025-03-28 15:30:58 -04:00
committed by GitHub
parent c0c3a387bb
commit 49a8114843
10 changed files with 39 additions and 24 deletions

View File

@@ -35,7 +35,7 @@ def define_env(env: "MacrosPlugin"):
src = src.replace( src = src.replace(
"QApplication([])", "QApplication.instance() or QApplication([])" "QApplication([])", "QApplication.instance() or QApplication([])"
) )
src = src.replace("app.exec_()", "") src = src.replace("app.exec_()", "app.processEvents()")
exec(src) exec(src)
_grab(dest, width) _grab(dest, width)
@@ -127,7 +127,6 @@ def define_env(env: "MacrosPlugin"):
def _grab(dest: str | Path, width) -> list[Path]: def _grab(dest: str | Path, width) -> list[Path]:
"""Grab the top widgets of the application.""" """Grab the top widgets of the application."""
from qtpy.QtCore import QTimer
from qtpy.QtWidgets import QApplication from qtpy.QtWidgets import QApplication
w = QApplication.topLevelWidgets()[-1] w = QApplication.topLevelWidgets()[-1]
@@ -135,12 +134,3 @@ def _grab(dest: str | Path, width) -> list[Path]:
w.activateWindow() w.activateWindow()
w.setMinimumHeight(40) w.setMinimumHeight(40)
w.grab().save(str(dest)) w.grab().save(str(dest))
# hack to make sure the object is truly closed and deleted
while True:
QTimer.singleShot(10, w.deleteLater)
QApplication.processEvents()
try:
w.parent()
except RuntimeError:
return

View File

@@ -11,7 +11,7 @@ running in the desired thread:
`ensure_object_thread` ensures that a decorated bound method of a `QObject` runs `ensure_object_thread` ensures that a decorated bound method of a `QObject` runs
in the thread in which the instance lives ([see qt documentation for in the thread in which the instance lives ([see qt documentation for
details](https://doc.qt.io/qt-5/threads-qobject.html#accessing-qobject-subclasses-from-other-threads)). details](https://doc.qt.io/qt-6/threads-qobject.html#accessing-qobject-subclasses-from-other-threads)).
## Usage ## Usage

View File

@@ -27,6 +27,7 @@ The following are QWidget subclasses:
| [`QSearchableTreeWidget`](./qsearchabletreewidget.md) | `QTreeWidget` variant with search field that filters available options | | [`QSearchableTreeWidget`](./qsearchabletreewidget.md) | `QTreeWidget` variant with search field that filters available options |
| [`QColorComboBox`](./qcolorcombobox.md) | `QComboBox` to select from a specified set of colors | | [`QColorComboBox`](./qcolorcombobox.md) | `QComboBox` to select from a specified set of colors |
| [`QColormapComboBox`](./qcolormap.md) | `QComboBox` to select from a specified set of colormaps. | | [`QColormapComboBox`](./qcolormap.md) | `QComboBox` to select from a specified set of colormaps. |
| [`QToggleSwitch`](./qtoggleswitch.md) | `QAbstractButton` that represents a boolean value with a toggle switch. |
## Frames and containers ## Frames and containers

View File

@@ -1,7 +1,7 @@
# QEnumComboBox # QEnumComboBox
`QEnumComboBox` is a variant of `QEnumComboBox` is a variant of
[`QComboBox`](https://doc.qt.io/qt-5/qcombobox.html) that populates the items in [`QComboBox`](https://doc.qt.io/qt-6/qcombobox.html) that populates the items in
the combobox based on a python `Enum` class. In addition to all the methods the combobox based on a python `Enum` class. In addition to all the methods
provided by `QComboBox`, this subclass adds the methods provided by `QComboBox`, this subclass adds the methods
`enumClass`/`setEnumClass` to get/set the current `Enum` class represented by `enumClass`/`setEnumClass` to get/set the current `Enum` class represented by

View File

@@ -20,7 +20,7 @@ app.exec_()
{{ show_widget() }} {{ show_widget() }}
- `QRangeSlider` inherits from [`QSlider`](https://doc.qt.io/qt-5/qslider.html) - `QRangeSlider` inherits from [`QSlider`](https://doc.qt.io/qt-6/qslider.html)
and attempts to match the Qt API as closely as possible and attempts to match the Qt API as closely as possible
- It uses platform-specific styles (for handle, groove, & ticks) but also supports - It uses platform-specific styles (for handle, groove, & ticks) but also supports
QSS style sheets. QSS style sheets.
@@ -28,9 +28,9 @@ app.exec_()
- Supports more than 2 handles (e.g. `slider.setValue([0, 10, 60, 80])`) - Supports more than 2 handles (e.g. `slider.setValue([0, 10, 60, 80])`)
As `QRangeSlider` inherits from As `QRangeSlider` inherits from
[`QtWidgets.QSlider`](https://doc.qt.io/qt-5/qslider.html), you can use all of [`QtWidgets.QSlider`](https://doc.qt.io/qt-6/qslider.html), you can use all of
the same methods available in the [QSlider the same methods available in the [QSlider
API](https://doc.qt.io/qt-5/qslider.html). The major difference is that `value()` API](https://doc.qt.io/qt-6/qslider.html). The major difference is that `value()`
and `sliderPosition()` are reimplemented as `tuples` of `int` (where the length of and `sliderPosition()` are reimplemented as `tuples` of `int` (where the length of
the tuple is equal to the number of handles in the slider.) the tuple is equal to the number of handles in the slider.)

View File

@@ -1,7 +1,7 @@
# QSearchableComboBox # QSearchableComboBox
`QSearchableComboBox` is a variant of `QSearchableComboBox` is a variant of
[`QComboBox`](https://doc.qt.io/qt-5/qcombobox.html) that allow to filter list [`QComboBox`](https://doc.qt.io/qt-6/qcombobox.html) that allow to filter list
of options by enter part of text. It could be drop in replacement for of options by enter part of text. It could be drop in replacement for
`QComboBox`. `QComboBox`.

View File

@@ -1,13 +1,13 @@
# QSearchableListWidget # QSearchableListWidget
`QSearchableListWidget` is a variant of `QSearchableListWidget` is a variant of
[`QListWidget`](https://doc.qt.io/qt-5/qlistwidget.html) that add text entry [`QListWidget`](https://doc.qt.io/qt-6/qlistwidget.html) that add text entry
above list widget that allow to filter list of available options. above list widget that allow to filter list of available options.
Due to implementation details, this widget it does not inherit directly from Due to implementation details, this widget it does not inherit directly from
[`QListWidget`](https://doc.qt.io/qt-5/qlistwidget.html) but it does fully [`QListWidget`](https://doc.qt.io/qt-6/qlistwidget.html) but it does fully
satisfy its api. The only limitation is that it cannot be used as argument of satisfy its api. The only limitation is that it cannot be used as argument of
[`QListWidgetItem`](https://doc.qt.io/qt-5/qlistwidgetitem.html) constructor. [`QListWidgetItem`](https://doc.qt.io/qt-6/qlistwidgetitem.html) constructor.
```python ```python
from qtpy.QtWidgets import QApplication from qtpy.QtWidgets import QApplication

View File

@@ -0,0 +1,24 @@
# QToggleSwitch
`QToggleSwitch` is a
[`QAbstractButton`](https://doc.qt.io/qt-6/qabstractbutton.html) subclass
that represents a boolean value as a toggle switch. The API is similar to
[`QCheckBox`](https://doc.qt.io/qt-6/qcheckbox.html) but with a different
visual representation.
```python
from qtpy.QtWidgets import QApplication
from superqt import QToggleSwitch
app = QApplication([])
switch = QToggleSwitch()
switch.show()
app.exec_()
```
{{ show_widget(80) }}
{{ show_members('superqt.QToggleSwitch') }}

View File

@@ -17,7 +17,7 @@ class QSearchableTreeWidget(QWidget):
into the `filter` line edit. An item is only shown if its, any of its ancestors', into the `filter` line edit. An item is only shown if its, any of its ancestors',
or any of its descendants' keys or values match this pattern. or any of its descendants' keys or values match this pattern.
The regular expression follows the conventions described by the Qt docs: The regular expression follows the conventions described by the Qt docs:
https://doc.qt.io/qt-5/qregularexpression.html#details https://doc.qt.io/qt-6/qregularexpression.html#details
Attributes Attributes
---------- ----------

View File

@@ -766,7 +766,7 @@ def thread_worker(
############################################################################ ############################################################################
# This is a variant on the above pattern, it uses QThread instead of Qrunnable # This is a variant on the above pattern, it uses QThread instead of Qrunnable
# see https://doc.qt.io/qt-5/threads-technologies.html#comparison-of-solutions # see https://doc.qt.io/qt-6/threads-technologies.html#comparison-of-solutions
# (it appears from that table that QRunnable cannot emit or receive signals, # (it appears from that table that QRunnable cannot emit or receive signals,
# but we circumvent that here with our WorkerBase class that also inherits from # but we circumvent that here with our WorkerBase class that also inherits from
# QObject... providing signals/slots). # QObject... providing signals/slots).
@@ -777,7 +777,7 @@ def thread_worker(
# #
# However, a disadvantage is that you have no access to (and therefore less # However, a disadvantage is that you have no access to (and therefore less
# control over) the QThread itself. See for example all of the methods # control over) the QThread itself. See for example all of the methods
# provided on the QThread object: https://doc.qt.io/qt-5/qthread.html # provided on the QThread object: https://doc.qt.io/qt-6/qthread.html
if TYPE_CHECKING: if TYPE_CHECKING:
@@ -808,7 +808,7 @@ def new_worker_qthread(
standard "single-threaded" signals & slots, note that inter-thread standard "single-threaded" signals & slots, note that inter-thread
signals and slots (automatically) use an event-based QueuedConnection, while signals and slots (automatically) use an event-based QueuedConnection, while
intra-thread signals use a DirectConnection. See [Signals and Slots Across intra-thread signals use a DirectConnection. See [Signals and Slots Across
Threads](https://doc.qt.io/qt-5/threads-qobject.html#signals-and-slots-across-threads>) Threads](https://doc.qt.io/qt-6/threads-qobject.html#signals-and-slots-across-threads>)
Parameters Parameters
---------- ----------