Skip to content

Commit 49a8114

Browse files
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>
1 parent c0c3a38 commit 49a8114

10 files changed

+39
-24
lines changed

docs/_macros.py

+1-11
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def show_widget(context, width: int = 500) -> list[Path]:
3535
src = src.replace(
3636
"QApplication([])", "QApplication.instance() or QApplication([])"
3737
)
38-
src = src.replace("app.exec_()", "")
38+
src = src.replace("app.exec_()", "app.processEvents()")
3939

4040
exec(src)
4141
_grab(dest, width)
@@ -127,20 +127,10 @@ def show_members(cls: str):
127127

128128
def _grab(dest: str | Path, width) -> list[Path]:
129129
"""Grab the top widgets of the application."""
130-
from qtpy.QtCore import QTimer
131130
from qtpy.QtWidgets import QApplication
132131

133132
w = QApplication.topLevelWidgets()[-1]
134133
w.setFixedWidth(width)
135134
w.activateWindow()
136135
w.setMinimumHeight(40)
137136
w.grab().save(str(dest))
138-
139-
# hack to make sure the object is truly closed and deleted
140-
while True:
141-
QTimer.singleShot(10, w.deleteLater)
142-
QApplication.processEvents()
143-
try:
144-
w.parent()
145-
except RuntimeError:
146-
return

docs/utilities/thread_decorators.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ running in the desired thread:
1111

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

1616
## Usage
1717

docs/widgets/index.md

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ The following are QWidget subclasses:
2727
| [`QSearchableTreeWidget`](./qsearchabletreewidget.md) | `QTreeWidget` variant with search field that filters available options |
2828
| [`QColorComboBox`](./qcolorcombobox.md) | `QComboBox` to select from a specified set of colors |
2929
| [`QColormapComboBox`](./qcolormap.md) | `QComboBox` to select from a specified set of colormaps. |
30+
| [`QToggleSwitch`](./qtoggleswitch.md) | `QAbstractButton` that represents a boolean value with a toggle switch. |
3031

3132
## Frames and containers
3233

docs/widgets/qenumcombobox.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# QEnumComboBox
22

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

docs/widgets/qrangeslider.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@ app.exec_()
2020

2121
{{ show_widget() }}
2222

23-
- `QRangeSlider` inherits from [`QSlider`](https://doc.qt.io/qt-5/qslider.html)
23+
- `QRangeSlider` inherits from [`QSlider`](https://doc.qt.io/qt-6/qslider.html)
2424
and attempts to match the Qt API as closely as possible
2525
- It uses platform-specific styles (for handle, groove, & ticks) but also supports
2626
QSS style sheets.
2727
- Supports mouse wheel events
2828
- Supports more than 2 handles (e.g. `slider.setValue([0, 10, 60, 80])`)
2929

3030
As `QRangeSlider` inherits from
31-
[`QtWidgets.QSlider`](https://doc.qt.io/qt-5/qslider.html), you can use all of
31+
[`QtWidgets.QSlider`](https://doc.qt.io/qt-6/qslider.html), you can use all of
3232
the same methods available in the [QSlider
33-
API](https://doc.qt.io/qt-5/qslider.html). The major difference is that `value()`
33+
API](https://doc.qt.io/qt-6/qslider.html). The major difference is that `value()`
3434
and `sliderPosition()` are reimplemented as `tuples` of `int` (where the length of
3535
the tuple is equal to the number of handles in the slider.)
3636

docs/widgets/qsearchablecombobox.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# QSearchableComboBox
22

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

docs/widgets/qsearchablelistwidget.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# QSearchableListWidget
22

33
`QSearchableListWidget` is a variant of
4-
[`QListWidget`](https://doc.qt.io/qt-5/qlistwidget.html) that add text entry
4+
[`QListWidget`](https://doc.qt.io/qt-6/qlistwidget.html) that add text entry
55
above list widget that allow to filter list of available options.
66

77
Due to implementation details, this widget it does not inherit directly from
8-
[`QListWidget`](https://doc.qt.io/qt-5/qlistwidget.html) but it does fully
8+
[`QListWidget`](https://doc.qt.io/qt-6/qlistwidget.html) but it does fully
99
satisfy its api. The only limitation is that it cannot be used as argument of
10-
[`QListWidgetItem`](https://doc.qt.io/qt-5/qlistwidgetitem.html) constructor.
10+
[`QListWidgetItem`](https://doc.qt.io/qt-6/qlistwidgetitem.html) constructor.
1111

1212
```python
1313
from qtpy.QtWidgets import QApplication

docs/widgets/qtoggleswitch.md

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# QToggleSwitch
2+
3+
`QToggleSwitch` is a
4+
[`QAbstractButton`](https://doc.qt.io/qt-6/qabstractbutton.html) subclass
5+
that represents a boolean value as a toggle switch. The API is similar to
6+
[`QCheckBox`](https://doc.qt.io/qt-6/qcheckbox.html) but with a different
7+
visual representation.
8+
9+
```python
10+
from qtpy.QtWidgets import QApplication
11+
12+
from superqt import QToggleSwitch
13+
14+
app = QApplication([])
15+
16+
switch = QToggleSwitch()
17+
switch.show()
18+
19+
app.exec_()
20+
```
21+
22+
{{ show_widget(80) }}
23+
24+
{{ show_members('superqt.QToggleSwitch') }}

src/superqt/selection/_searchable_tree_widget.py

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

src/superqt/utils/_qthreading.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ def worker_function(*args, **kwargs):
766766
############################################################################
767767

768768
# This is a variant on the above pattern, it uses QThread instead of Qrunnable
769-
# see https://doc.qt.io/qt-5/threads-technologies.html#comparison-of-solutions
769+
# see https://doc.qt.io/qt-6/threads-technologies.html#comparison-of-solutions
770770
# (it appears from that table that QRunnable cannot emit or receive signals,
771771
# but we circumvent that here with our WorkerBase class that also inherits from
772772
# QObject... providing signals/slots).
@@ -777,7 +777,7 @@ def worker_function(*args, **kwargs):
777777
#
778778
# However, a disadvantage is that you have no access to (and therefore less
779779
# control over) the QThread itself. See for example all of the methods
780-
# provided on the QThread object: https://doc.qt.io/qt-5/qthread.html
780+
# provided on the QThread object: https://doc.qt.io/qt-6/qthread.html
781781

782782
if TYPE_CHECKING:
783783

@@ -808,7 +808,7 @@ def new_worker_qthread(
808808
standard "single-threaded" signals & slots, note that inter-thread
809809
signals and slots (automatically) use an event-based QueuedConnection, while
810810
intra-thread signals use a DirectConnection. See [Signals and Slots Across
811-
Threads](https://doc.qt.io/qt-5/threads-qobject.html#signals-and-slots-across-threads>)
811+
Threads](https://doc.qt.io/qt-6/threads-qobject.html#signals-and-slots-across-threads>)
812812
813813
Parameters
814814
----------

0 commit comments

Comments
 (0)