# SwitchControl for PyQt6 <br/> (forked from [Prx001/QSwitchControl](https://github.com/Prx001/QSwitchControl))
## Custom toggle-switch widget implemented for \*PyQt6\* applications!
##
https://user-images.githubusercontent.com/67240789/128912103-b24d7321-a7d6-4b1b-bbdc-562dbd20b358.mp4
### An easy-to-use and modern toggle switch for Qt Python binding PyQt
PyQt6_SwitchControl is a custom toggle-switch widget inherited from 'QCheckBox' class, and acts as a checkbox alternative widget in your PyQt6 application.
>This repository is a fork from [Prx001](https://github.com/Prx001/)'s [QSwitchControl](https://github.com/Prx001/QSwitchControl) project but the code has been modified to work with PyQt6.
## How to use?
### Installation
The package is available on [PyPi](https://pypi.org/project/PyQt6_SwitchControl) so as always use pip for installation:
```
pip install PyQt6_SwitchControl
```
### Usage in your Python application
First of all, as expected, you need to import the package.
Import 'SwitchControl' class from the package:
```python
from PyQt6_SwitchControl import SwitchControl
```
Now the class is ready to use!
SwitchControl is an alternative widget for QCheckBox from Qt framework, same methods, same usage and that's how it works.
There are things you can define for your SwitchControl, like the circle color, background color, active color, animation easing curve, animation duration and some other things, but you can use default values. The package contains a '__main__' script, so you can test the widget easily:
```
python -m PyQt6_SwitchControl
```
Bellow is the '__main__' script:
```python
import sys
from PyQt6.QtCore import Qt
from PyQt6.QtWidgets import QApplication, QWidget, QHBoxLayout
from PyQt6_SwitchControl import SwitchControl
class Form(QWidget):
def __init__(self):
super().__init__()
self.init_ui()
def init_ui(self):
self.resize(400, 400)
self.setWindowTitle("SwitchControl test")
self.setStyleSheet("""
background-color: #222222;
""")
switch_control = SwitchControl()
h_box = QHBoxLayout()
h_box.addWidget(switch_control, Qt.AlignmentFlag.AlignCenter, Qt.AlignmentFlag.AlignCenter)
self.setLayout(h_box)
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
form = Form()
form.show()
app.exec()
```
In this script we used the default values for our widget:
```python
switch_control = SwitchControl()
```
You can define the values yourself. Bellow is an example:
```python
switch_control = SwitchControl(bg_color="#777777", circle_color="#DDD", active_color="#aa00ff", animation_curve=QtCore.QEasingCurve.InOutCubic, animation_duration=300, checked=True, change_cursor=False)
```
# Qt Designer integration
Qt Designer is a very extensible tool, even can support your custom widgets!
It means you can interact with your custom widget just as you do with Qt
widgets, like QPushButton, QCheckBox, you can drag and drop them on your
form, change their sizes, set properties and so on. Qt Designer can load
plugins, and you can load your custom widgets through plugins, then your
custom widget is available in Qt Designer Widget Box. In C++, using Qt
Creator IDE you can create your custom widgets and compile them to .dll file,
then you put the dll file (your plugin) into Qt Designer's relative path for
plugins, and that's it you can use your widget in Designer. But, here in python
the story is a little different. PyQt supports this plugin development and
integrate *Python based* Qt custom widgets in Qt Designer. [Learn more about integrating PyQt custom widgets in Qt Designer](https://wiki.python.org/moin/PyQt/Using_Python_Custom_Widgets_in_Qt_Designer)
There is the Qt Designer
plugin for PyQt6_SwitchControl in package, [PyQt6_SwitchControl_plugin.py](https://github.com/M1GW/PyQt6_SwitchControl/blob/main/PyQt6_SwitchControl/PyQt6_SwitchControl_plugin.py).
You can load it to your Qt Designer.
Raw data
{
"_id": null,
"home_page": "https://github.com/M1GW/PyQt6_SwitchControl",
"name": "PyQt6-SwitchControl",
"maintainer": "M1GW",
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "PyQt, PyQt6, switch, toggle, toggle-button, toggle-switch, qt6-widgets, qt",
"author": "Parsa.py",
"author_email": "\"Parsa.py\" <munichbayern2005@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/be/c8/ef4a7d8af38ead06e4a1e124a2bded7e0192e270129c43426b64fbe568c2/pyqt6_switchcontrol-1.0.4.post1.tar.gz",
"platform": null,
"description": "# SwitchControl for PyQt6 <br/> (forked from [Prx001/QSwitchControl](https://github.com/Prx001/QSwitchControl))\r\n## Custom toggle-switch widget implemented for \\*PyQt6\\* applications!\r\n## \r\n\r\nhttps://user-images.githubusercontent.com/67240789/128912103-b24d7321-a7d6-4b1b-bbdc-562dbd20b358.mp4\r\n\r\n\r\n\r\n### An easy-to-use and modern toggle switch for Qt Python binding PyQt\r\nPyQt6_SwitchControl is a custom toggle-switch widget inherited from 'QCheckBox' class, and acts as a checkbox alternative widget in your PyQt6 application.\r\n>This repository is a fork from [Prx001](https://github.com/Prx001/)'s [QSwitchControl](https://github.com/Prx001/QSwitchControl) project but the code has been modified to work with PyQt6.\r\n\r\n## How to use?\r\n### Installation\r\nThe package is available on [PyPi](https://pypi.org/project/PyQt6_SwitchControl) so as always use pip for installation:\r\n```\r\npip install PyQt6_SwitchControl\r\n```\r\n\r\n### Usage in your Python application\r\nFirst of all, as expected, you need to import the package.\r\nImport 'SwitchControl' class from the package:\r\n```python\r\nfrom PyQt6_SwitchControl import SwitchControl\r\n```\r\nNow the class is ready to use!\r\nSwitchControl is an alternative widget for QCheckBox from Qt framework, same methods, same usage and that's how it works.\r\nThere are things you can define for your SwitchControl, like the circle color, background color, active color, animation easing curve, animation duration and some other things, but you can use default values. The package contains a '__main__' script, so you can test the widget easily:\r\n```\r\npython -m PyQt6_SwitchControl\r\n```\r\nBellow is the '__main__' script:\r\n```python\r\nimport sys\r\n\r\nfrom PyQt6.QtCore import Qt\r\nfrom PyQt6.QtWidgets import QApplication, QWidget, QHBoxLayout\r\n\r\nfrom PyQt6_SwitchControl import SwitchControl\r\n\r\n\r\nclass Form(QWidget):\r\n def __init__(self):\r\n super().__init__()\r\n self.init_ui()\r\n\r\n def init_ui(self):\r\n self.resize(400, 400)\r\n self.setWindowTitle(\"SwitchControl test\")\r\n self.setStyleSheet(\"\"\"\r\n\t\tbackground-color: #222222;\r\n\t\t\"\"\")\r\n switch_control = SwitchControl()\r\n h_box = QHBoxLayout()\r\n h_box.addWidget(switch_control, Qt.AlignmentFlag.AlignCenter, Qt.AlignmentFlag.AlignCenter)\r\n self.setLayout(h_box)\r\n self.show()\r\n\r\n\r\nif __name__ == '__main__':\r\n app = QApplication(sys.argv)\r\n form = Form()\r\n form.show()\r\n app.exec()\r\n```\r\nIn this script we used the default values for our widget:\r\n```python\r\nswitch_control = SwitchControl()\r\n```\r\nYou can define the values yourself. Bellow is an example:\r\n```python\r\nswitch_control = SwitchControl(bg_color=\"#777777\", circle_color=\"#DDD\", active_color=\"#aa00ff\", animation_curve=QtCore.QEasingCurve.InOutCubic, animation_duration=300, checked=True, change_cursor=False)\r\n```\r\n# Qt Designer integration\r\nQt Designer is a very extensible tool, even can support your custom widgets!\r\nIt means you can interact with your custom widget just as you do with Qt \r\nwidgets, like QPushButton, QCheckBox, you can drag and drop them on your \r\nform, change their sizes, set properties and so on. Qt Designer can load \r\nplugins, and you can load your custom widgets through plugins, then your \r\ncustom widget is available in Qt Designer Widget Box. In C++, using Qt \r\nCreator IDE you can create your custom widgets and compile them to .dll file, \r\nthen you put the dll file (your plugin) into Qt Designer's relative path for \r\nplugins, and that's it you can use your widget in Designer. But, here in python \r\nthe story is a little different. PyQt supports this plugin development and \r\nintegrate *Python based* Qt custom widgets in Qt Designer. [Learn more about integrating PyQt custom widgets in Qt Designer](https://wiki.python.org/moin/PyQt/Using_Python_Custom_Widgets_in_Qt_Designer) \r\nThere is the Qt Designer \r\nplugin for PyQt6_SwitchControl in package, [PyQt6_SwitchControl_plugin.py](https://github.com/M1GW/PyQt6_SwitchControl/blob/main/PyQt6_SwitchControl/PyQt6_SwitchControl_plugin.py).\r\nYou can load it to your Qt Designer.\r\n",
"bugtrack_url": null,
"license": "LICENSE",
"summary": "An easy-to-use and modern toggle switch for Qt Python binding PyQt",
"version": "1.0.4.post1",
"project_urls": {
"Homepage": "https://github.com/M1GW/PyQt6_SwitchControl",
"Issues": "https://github.com/M1GW/PyQt6_SwitchControl/issues",
"Repository": "https://github.com/M1GW/PyQt6_SwitchControl"
},
"split_keywords": [
"pyqt",
" pyqt6",
" switch",
" toggle",
" toggle-button",
" toggle-switch",
" qt6-widgets",
" qt"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "10eaa719ed5ed6e30e7bb8cce736f86c7d17f9fcdc9afc63c7ee3c43a8b7c01c",
"md5": "50bc8a0c76c6a75d5475afc5ccb0140b",
"sha256": "4a6e80d02f6bb2dcf7abf571b30ec7a69ac3c9909691a95aaf31079ee1839d8b"
},
"downloads": -1,
"filename": "PyQt6_SwitchControl-1.0.4.post1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "50bc8a0c76c6a75d5475afc5ccb0140b",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 10003,
"upload_time": "2024-08-05T20:35:42",
"upload_time_iso_8601": "2024-08-05T20:35:42.165820Z",
"url": "https://files.pythonhosted.org/packages/10/ea/a719ed5ed6e30e7bb8cce736f86c7d17f9fcdc9afc63c7ee3c43a8b7c01c/PyQt6_SwitchControl-1.0.4.post1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "bec8ef4a7d8af38ead06e4a1e124a2bded7e0192e270129c43426b64fbe568c2",
"md5": "89b4f3c430d42dd06b7c90ff8025240a",
"sha256": "a9dfb6bc7e249122c21df640bdf70f61dec86367c613ee841a80bb91bc62141e"
},
"downloads": -1,
"filename": "pyqt6_switchcontrol-1.0.4.post1.tar.gz",
"has_sig": false,
"md5_digest": "89b4f3c430d42dd06b7c90ff8025240a",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 6352,
"upload_time": "2024-08-05T20:35:43",
"upload_time_iso_8601": "2024-08-05T20:35:43.773937Z",
"url": "https://files.pythonhosted.org/packages/be/c8/ef4a7d8af38ead06e4a1e124a2bded7e0192e270129c43426b64fbe568c2/pyqt6_switchcontrol-1.0.4.post1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-05 20:35:43",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "M1GW",
"github_project": "PyQt6_SwitchControl",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "pyqt6-switchcontrol"
}