# PyQt Advanced Slider
[![PyPI](https://img.shields.io/badge/pypi-v1.1.1-blue)](https://pypi.org/project/pyqt-advanced-slider/)
[![Python](https://img.shields.io/badge/python-3.7+-blue)](https://github.com/niklashenning/pyqt-advanced-slider)
[![Build](https://img.shields.io/badge/build-passing-neon)](https://github.com/niklashenning/pyqt-advanced-slider)
[![Coverage](https://img.shields.io/badge/coverage-99%25-green)](https://github.com/niklashenning/pyqt-advanced-slider)
[![License](https://img.shields.io/badge/license-MIT-green)](https://github.com/niklashenning/pyqt-advanced-slider/blob/master/LICENSE)
A clean and customizable int and float slider widget for PyQt and PySide
![pyqt-advanced-slider](https://github.com/niklashenning/pyqt-modern-slider/assets/58544929/b741e06c-1efa-44c8-8c7e-e35ca1c0f348)
## Features
* Supports `int` and `float`
* 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`, and `PySide6`
## Installation
```
pip install pyqt-advanced-slider
```
## Usage
Import the `Slider` class and add it to your window like any other PyQt Widget:
```python
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:
```python
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:
```python
value = slider.getValue() # 2500.0
value_formatted = slider.getValueFormatted() # e.g. '~2,500.00 €'
```
> **NOTE:** <br>When getting the value of the slider using the `getValue()` method or by subscribing to the `valueChanged` event, it will either be an `int` or a `float`, depending on whether float values are enabled or disabled for the slider.
## Customization
* **Making the slider a float slider:**
```python
slider.setFloat(True) # Default: False
slider.setDecimals(2) # Default: 1
```
* **Adding a prefix and a suffix:**
```python
slider.setPrefix('~') # Default: empty string
slider.setSuffix(' €') # Default: empty string
```
> **EXAMPLE:** <br>The value `100` formatted with `~` as the prefix and `°` as the suffix would be shown as `~100°`
* **Customizing the formatting of the value shown on the slider:**
```python
slider.setDecimalSeparator(',') # Default: '.'
slider.setThousandsSeparator('.') # Default: empty string
```
> **EXAMPLE:** <br>The value `1052.17` formatted with `,` as the decimal separator and `.` as the thousands separator would be `1.052,17`
* **Changing how much the value is incremented or decremented on keyboard and mouse inputs:**
```python
# 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<br>
> **PAGE STEP:** Increment or decrement of the value when the PageUp or PageDown key is pressed
* **Hiding the value on the slider completely:**
```python
slider.showValue(False) # Default: True
```
* **Enabling or disabling keyboard and mouse wheel input:**
```python
slider.setKeyboardInputEnabled(False) # Default: True
slider.setMouseWheelInputEnabled(False) # Default: True
```
* **Setting custom colors:**
```python
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:**
```python
slider.setBorderRadius(3) # Default: 0
```
* **Setting a custom font:**
```python
# 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](examples) folder.
## Tests
Installing the required test dependencies [pytest](https://github.com/pytest-dev/pytest), [pytest-qt](https://github.com/pytest-dev/pytest-qt), [coveragepy](https://github.com/nedbat/coveragepy), and [PyQt6](https://pypi.org/project/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](LICENSE).
Raw data
{
"_id": null,
"home_page": "https://github.com/niklashenning/pyqt-advanced-slider",
"name": "pyqt-advanced-slider",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": "python, pyqt, qt, slider, int slider, float slider",
"author": "Niklas Henning",
"author_email": "business@niklashenning.com",
"download_url": "https://files.pythonhosted.org/packages/bf/8a/f6efa450c46b8cc7ba5febeff5d601b68e1d8dd71b68c2b900cbfee9baa9/pyqt-advanced-slider-1.1.1.tar.gz",
"platform": null,
"description": "\r\n# PyQt Advanced Slider\r\n\r\n[![PyPI](https://img.shields.io/badge/pypi-v1.1.1-blue)](https://pypi.org/project/pyqt-advanced-slider/)\r\n[![Python](https://img.shields.io/badge/python-3.7+-blue)](https://github.com/niklashenning/pyqt-advanced-slider)\r\n[![Build](https://img.shields.io/badge/build-passing-neon)](https://github.com/niklashenning/pyqt-advanced-slider)\r\n[![Coverage](https://img.shields.io/badge/coverage-99%25-green)](https://github.com/niklashenning/pyqt-advanced-slider)\r\n[![License](https://img.shields.io/badge/license-MIT-green)](https://github.com/niklashenning/pyqt-advanced-slider/blob/master/LICENSE)\r\n\r\nA clean and customizable int and float slider widget for PyQt and PySide\r\n\r\n![pyqt-advanced-slider](https://github.com/niklashenning/pyqt-modern-slider/assets/58544929/b741e06c-1efa-44c8-8c7e-e35ca1c0f348)\r\n\r\n## Features\r\n* Supports `int` and `float`\r\n* Supports dynamic switching between types\r\n* Customizable decimal places\r\n* Customizable prefix and suffix\r\n* Customizable decimal separator and thousands separator\r\n* Supports keyboard and mouse wheel inputs\r\n* Modern and customizable UI\r\n* Works with `PyQt5`, `PyQt6`, `PySide2`, and `PySide6`\r\n\r\n## Installation\r\n```\r\npip install pyqt-advanced-slider\r\n```\r\n\r\n## Usage\r\nImport the `Slider` class and add it to your window like any other PyQt Widget:\r\n```python\r\nfrom PyQt6.QtWidgets import QMainWindow\r\nfrom pyqt_advanced_slider import Slider\r\n\r\n\r\nclass Window(QMainWindow):\r\n def __init__(self):\r\n super().__init__(parent=None)\r\n\r\n slider = Slider(self) # Add slider\r\n slider.setRange(-50, 100) # Set min and max\r\n slider.setValue(25) # Set value\r\n slider.valueChanged.connect(self.slider_value_changed) # Connect change event\r\n \r\n # Called every time the slider value changes\r\n def slider_value_changed(self, value):\r\n print(value)\r\n```\r\n\r\nYou can also set the minimum and maximum of the slider individually with the `setMinimum()` and `setMaximum()` methods:\r\n```python\r\nslider.setMinimum(-50) # Default: 0\r\nslider.setMaximum(100) # Default: 10\r\n```\r\n\r\nThe `getValue()` method returns the current value while the `getValueFormatted()` method returns the value as the formatted string that is being displayed on the slider:\r\n```python\r\nvalue = slider.getValue() # 2500.0\r\nvalue_formatted = slider.getValueFormatted() # e.g. '~2,500.00 \u00e2\u201a\u00ac'\r\n```\r\n\r\n> **NOTE:** <br>When getting the value of the slider using the `getValue()` method or by subscribing to the `valueChanged` event, it will either be an `int` or a `float`, depending on whether float values are enabled or disabled for the slider.\r\n\r\n## Customization\r\n\r\n* **Making the slider a float slider:**\r\n```python\r\nslider.setFloat(True) # Default: False\r\nslider.setDecimals(2) # Default: 1\r\n```\r\n\r\n* **Adding a prefix and a suffix:**\r\n```python\r\nslider.setPrefix('~') # Default: empty string\r\nslider.setSuffix(' \u00e2\u201a\u00ac') # Default: empty string\r\n```\r\n\r\n> **EXAMPLE:** <br>The value `100` formatted with `~` as the prefix and `\u00c2\u00b0` as the suffix would be shown as `~100\u00c2\u00b0`\r\n\r\n\r\n* **Customizing the formatting of the value shown on the slider:**\r\n```python\r\nslider.setDecimalSeparator(',') # Default: '.'\r\nslider.setThousandsSeparator('.') # Default: empty string\r\n```\r\n> **EXAMPLE:** <br>The value `1052.17` formatted with `,` as the decimal separator and `.` as the thousands separator would be `1.052,17`\r\n\r\n* **Changing how much the value is incremented or decremented on keyboard and mouse inputs:**\r\n```python\r\n# If left default, the single step and page step will be 1% and 5% of the slider's value range\r\nslider.setSingleStep(10) # Default: 0\r\nslider.setPageStep(25) # Default: 0\r\n```\r\n\r\n> **SINGLE STEP:** Increment or decrement of the value when the slider is scrolled or the arrow keys are pressed<br>\r\n> **PAGE STEP:** Increment or decrement of the value when the PageUp or PageDown key is pressed\r\n\r\n* **Hiding the value on the slider completely:**\r\n```python\r\nslider.showValue(False) # Default: True\r\n```\r\n\r\n* **Enabling or disabling keyboard and mouse wheel input:**\r\n```python\r\nslider.setKeyboardInputEnabled(False) # Default: True\r\nslider.setMouseWheelInputEnabled(False) # Default: True\r\n```\r\n\r\n* **Setting custom colors:**\r\n```python\r\nslider.setTextColor(QColor('#0F0F0F')) # Default: #000000\r\nslider.setBackgroundColor(QColor('#FFFFFF')) # Default: #D6D6D6\r\nslider.setAccentColor(QColor.fromRgb(100, 100, 100)) # Default: #0078D7\r\nslider.setBorderColor(QColor.fromRgb(0, 0, 0)) # Default: #D1CFD3\r\n```\r\n\r\n* **Making the corners rounded:**\r\n```python\r\nslider.setBorderRadius(3) # Default: 0\r\n```\r\n\r\n* **Setting a custom font:**\r\n```python\r\n# Init font\r\nfont = QFont()\r\nfont.setFamily('Times')\r\nfont.setPointSize(10)\r\nfont.setBold(True)\r\n\r\n# Set font\r\nslider.setFont(font)\r\n```\r\n\r\nExamples for PyQt5, PyQt6, and PySide6 can be found in the [examples](examples) folder.\r\n\r\n## Tests\r\nInstalling the required test dependencies [pytest](https://github.com/pytest-dev/pytest), [pytest-qt](https://github.com/pytest-dev/pytest-qt), [coveragepy](https://github.com/nedbat/coveragepy), and [PyQt6](https://pypi.org/project/PyQt6):\r\n```\r\npip install pytest pytest-qt coverage PyQt6\r\n```\r\n\r\nTo run the tests with coverage, clone this repository, go into the main directory and run:\r\n```\r\ncoverage run -m pytest\r\ncoverage report --ignore-errors -m\r\n```\r\n\r\n## License\r\nThis software is licensed under the [MIT license](LICENSE).\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A clean and customizable int and float slider widget for PyQt and PySide",
"version": "1.1.1",
"project_urls": {
"Homepage": "https://github.com/niklashenning/pyqt-advanced-slider"
},
"split_keywords": [
"python",
" pyqt",
" qt",
" slider",
" int slider",
" float slider"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "1eb2bcaccebc3845296bc5db0e8f86d68293b2f9c3f65a82e9083a1de6784c5f",
"md5": "7e00e110efb7774947dc73ee2d92c9ef",
"sha256": "a40b454393db1d13edd52a03a4b1ee37055c2dcde12bc7f614fe424112373980"
},
"downloads": -1,
"filename": "pyqt_advanced_slider-1.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "7e00e110efb7774947dc73ee2d92c9ef",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 9173,
"upload_time": "2024-06-23T22:10:53",
"upload_time_iso_8601": "2024-06-23T22:10:53.382536Z",
"url": "https://files.pythonhosted.org/packages/1e/b2/bcaccebc3845296bc5db0e8f86d68293b2f9c3f65a82e9083a1de6784c5f/pyqt_advanced_slider-1.1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "bf8af6efa450c46b8cc7ba5febeff5d601b68e1d8dd71b68c2b900cbfee9baa9",
"md5": "97708ae0577367d438bf181efd3fb0a8",
"sha256": "2f1fb78186aa4d9f0b35a176b1deedbfb8c57ce9ab4029ec6e5118e76cf03e96"
},
"downloads": -1,
"filename": "pyqt-advanced-slider-1.1.1.tar.gz",
"has_sig": false,
"md5_digest": "97708ae0577367d438bf181efd3fb0a8",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 10814,
"upload_time": "2024-06-23T22:10:54",
"upload_time_iso_8601": "2024-06-23T22:10:54.505098Z",
"url": "https://files.pythonhosted.org/packages/bf/8a/f6efa450c46b8cc7ba5febeff5d601b68e1d8dd71b68c2b900cbfee9baa9/pyqt-advanced-slider-1.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-06-23 22:10:54",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "niklashenning",
"github_project": "pyqt-advanced-slider",
"travis_ci": false,
"coveralls": true,
"github_actions": false,
"requirements": [
{
"name": "QtPy",
"specs": [
[
">=",
"2.4.1"
]
]
}
],
"lcname": "pyqt-advanced-slider"
}