PyQt Advanced Slider
A clean and customizable int and float slider widget for PyQt and PySide
Features
- Supports
intandfloat - Supports dynamic switching between types
- Customizable decimal places
- Customizable prefix and suffix
- Customizable decimal separator and thousands separator
- Supports keyboard and mouse wheel inputs
- Modern and customizable UI
- Works with
PyQt5,PyQt6,PySide2, andPySide6
Installation
pip install pyqt-advanced-slider
Usage
Import the Slider class and add it to your window like any other PyQt Widget:
from PyQt6.QtWidgets import QMainWindow
from pyqt_advanced_slider import Slider
class Window(QMainWindow):
def __init__(self):
super().__init__(parent=None)
slider = Slider(self) # Add slider
slider.setRange(-50, 100) # Set min and max
slider.setValue(25) # Set value
slider.valueChanged.connect(self.slider_value_changed) # Connect change event
# Called every time the slider value changes
def slider_value_changed(self, value):
print(value)
You can also set the minimum and maximum of the slider individually with the setMinimum() and setMaximum() methods:
slider.setMinimum(-50) # Default: 0
slider.setMaximum(100) # Default: 10
The getValue() method returns the current value while the getValueFormatted() method returns the value as the formatted string that is being displayed on the slider:
value = slider.getValue() # 2500.0
value_formatted = slider.getValueFormatted() # e.g. '~2,500.00 €'
NOTE:
When getting the value of the slider using thegetValue()method or by subscribing to thevalueChangedevent, it will either be anintor afloat, depending on whether float values are enabled or disabled for the slider.
Customization
- Making the slider a float slider:
slider.setFloat(True) # Default: False
slider.setDecimals(2) # Default: 1
- Adding a prefix and a suffix:
slider.setPrefix('~') # Default: empty string
slider.setSuffix(' €') # Default: empty string
EXAMPLE:
The value100formatted with~as the prefix and°as the suffix would be shown as~100°
- Customizing the formatting of the value shown on the slider:
slider.setDecimalSeparator(',') # Default: '.'
slider.setThousandsSeparator('.') # Default: empty string
EXAMPLE:
The value1052.17formatted with,as the decimal separator and.as the thousands separator would be1.052,17
- Changing how much the value is incremented or decremented on keyboard and mouse inputs:
# If left default, the single step and page step will be 1% and 5% of the slider's value range
slider.setSingleStep(10) # Default: 0
slider.setPageStep(25) # Default: 0
SINGLE STEP: Increment or decrement of the value when the slider is scrolled or the arrow keys are pressed
PAGE STEP: Increment or decrement of the value when the PageUp or PageDown key is pressed
- Hiding the value on the slider completely:
slider.showValue(False) # Default: True
- Enabling or disabling keyboard and mouse wheel input:
slider.setKeyboardInputEnabled(False) # Default: True
slider.setMouseWheelInputEnabled(False) # Default: True
- Setting custom colors:
slider.setTextColor(QColor('#0F0F0F')) # Default: #000000
slider.setBackgroundColor(QColor('#FFFFFF')) # Default: #D6D6D6
slider.setAccentColor(QColor.fromRgb(100, 100, 100)) # Default: #0078D7
slider.setBorderColor(QColor.fromRgb(0, 0, 0)) # Default: #D1CFD3
- Making the corners rounded:
slider.setBorderRadius(3) # Default: 0
- Setting a custom font:
# Init font
font = QFont()
font.setFamily('Times')
font.setPointSize(10)
font.setBold(True)
# Set font
slider.setFont(font)
Examples for PyQt5, PyQt6, and PySide6 can be found in the examples folder.
Tests
Installing the required test dependencies pytest, pytest-qt, coveragepy, and PyQt6:
pip install pytest pytest-qt coverage PyQt6
To run the tests with coverage, clone this repository, go into the main directory and run:
coverage run -m pytest
coverage report --ignore-errors -m
License
This software is licensed under the MIT license.
Metadata
Release files for pyqt-advanced-slider 1.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pyqt-advanced-slider-1.1.1.tar.gz | 10.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pyqt_advanced_slider-1.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 20.0 kB
Release files / pyqt-advanced-slider-1.1.1.tar.gz
| Download URL | pyqt-advanced-slider-1.1.1.tar.gz |
|---|---|
| Size | 10.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2f1fb78186aa4d9f0b35a176b1deedbfb8c57ce9ab4029ec6e5118e76cf03e96
|
|
BLAKE2b-256 checksum How to use checksums |
bf8af6efa450c46b8cc7ba5febeff5d601b68e1d8dd71b68c2b900cbfee9baa9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.11.3
|
Release files / pyqt_advanced_slider-1.1.1-py3-none-any.whl
| Download URL | pyqt_advanced_slider-1.1.1-py3-none-any.whl |
|---|---|
| Size | 9.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a40b454393db1d13edd52a03a4b1ee37055c2dcde12bc7f614fe424112373980
|
|
BLAKE2b-256 checksum How to use checksums |
1eb2bcaccebc3845296bc5db0e8f86d68293b2f9c3f65a82e9083a1de6784c5f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.11.3
|