A clean and customizable int and float slider widget for PyQt and PySide
Project description
PyQt Advanced Slider
A clean and customizable int and float slider widget for PyQt and PySide
Features
- Supports
int
andfloat
- 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 thevalueChanged
event, it will either be anint
or 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 value100
formatted 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.17
formatted 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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for pyqt-advanced-slider-1.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 65e33c1c04a71db75a168bb3d2385196e5f94209e15627faf136c8df52a96d31 |
|
MD5 | 77e6628d6104a7d9ba0569937144e35c |
|
BLAKE2b-256 | 738599139eac6b07b9230a6c4e8ab1ea2f76feeecbbb235f0716ada9b657edc2 |
Hashes for pyqt_advanced_slider-1.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2f891de1c15c754882efe25fd27181a9e5ebc5abb7a2eb7f0476599eada53ecc |
|
MD5 | c290bb8803c8cb4518af795c165698fc |
|
BLAKE2b-256 | 09450e514d4d6288756c5541faa9dc6d98af81102c4a7326f5df0a6f840e51c4 |