Skip to main content

QSwitchControl

Custom toggle-switch widget implemented in PyQt5 for PyQt5 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

QSwitchControl is a custom toggle-switch widget inherited from 'QCheckBox' class, and acts as a checkbox alternative widget in your PyQt5 application.

How to use?

Installation

The package is available on PyPi so as always use pip for installation:

pip install QSwitchControl

Usage in your Python application

First of all, as expected, you need to import the package. Import 'SwitchControl' class from the package:

from QSwitchControl 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 QSwitchControl

Bellow is the 'main' script:

import sys

from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication, QWidget, QHBoxLayout

from QSwitchControl import SwitchControl


class Form(QWidget):
	def __init__(self):
		super().__init__()
		self.initUI()

	def initUI(self):
		self.resize(400, 400)
		self.setWindowTitle("SwitchControl test")
		self.setStyleSheet("""
		background-color: #222222;
		""")
		switch_control = SwitchControl()
		hbox = QHBoxLayout()
		hbox.addWidget(switch_control, Qt.AlignCenter, Qt.AlignCenter)
		self.setLayout(hbox)
		self.show()


app = QApplication(sys.argv)
form = Form()
if __name__ == '__main__':
	sys.exit(app.exec_())

In this script we used the default values for our widget:

switch_control = SwitchControl()

You can define the values yourself. Bellow is an example:

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 developement and integrate Python based Qt custom widgets in Qt Designer. Learn more about integrating PyQt custom widgets in Qt Designer There is the Qt Designer plugin for QSwitchControl in package, QSwitchControlplugin.py. You can load it to your Qt Designer.

Release files for QSwitchControl 1.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for QSwitchControl 1.0.4
File Size Uploaded
QSwitchControl-1.0.4.tar.gz 5.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for QSwitchControl 1.0.4
File Interpreter ABI Platform
QSwitchControl-1.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 13.5 kB

Release files / QSwitchControl-1.0.4.tar.gz

Download URL QSwitchControl-1.0.4.tar.gz
Size 5.3 kB
Tags Source
SHA-256 checksum
How to use checksums
5b7487c79a329a7ffa4c616cf4f41e8c8f9f3af203b9b5b910952d970a449eca
BLAKE2b-256 checksum
How to use checksums
3fc4086417dfc64e57b57dde07052620bae9d69789e9ae5e71bebe3965cce2c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.0

Release files / QSwitchControl-1.0.4-py3-none-any.whl

Download URL QSwitchControl-1.0.4-py3-none-any.whl
Size 8.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5871f0ba34fb8db6cc9f0858835b58fd6b263311ba159d74ed84d236662aa66d
BLAKE2b-256 checksum
How to use checksums
5591928b72944802726e2cf9e25ff4b4b38cb9579a8b4053ada774d67e8113a0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.0

Release history Release notifications | RSS feed

This release

1.0.4 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page