Multi-handle range slider widget for PyQt/PySide

Overview

QtRangeSlider

License PyPI Python Version Test codecov

The missing multi-handle range slider widget for PyQt & PySide

slider

The goal of this package is to provide a Range Slider (a slider with 2 or more handles) that feels as "native" as possible. Styles should match the OS by default, and the slider should behave like a standard QSlider... but with multiple handles!

  • QRangeSlider inherits from QSlider and attempts to match the Qt API as closely as possible
  • Uses platform-specific styles (for handle, groove, & ticks) but also supports QSS style sheets.
  • Supports mouse wheel and keypress (soon) events
  • Supports PyQt5, PyQt6, PySide2 and PySide6
  • Supports more than 2 handles (e.g. slider.setValue([0, 10, 60, 80]))

Installation

You can install QtRangeSlider via pip:

pip install qtrangeslider

# NOTE: you must also install a Qt Backend.
# PyQt5, PySide2, PyQt6, and PySide6 are supported
# As a convenience you can install them as extras:
pip install qtrangeslider[pyqt5]

API

To create a slider:

from qtrangeslider import QRangeSlider

# as usual:
# you must create a QApplication before create a widget.
range_slider = QRangeSlider()

As QRangeSlider inherits from QtWidgets.QSlider, you can use all of the same methods available in the QSlider API. The major difference is that value and sliderPosition are reimplemented as tuples of int (where the length of the tuple is equal to the number of handles in the slider.)

value: Tuple[int, ...]

This property holds the current value of all handles in the slider.

The slider forces all values to be within the legal range: minimum <= value <= maximum.

Changing the value also changes the sliderPosition.

Access Functions:
range_slider.value() -> Tuple[int, ...]
range_slider.setValue(val: Sequence[int]) -> None
Notifier Signal:
valueChanged(Tuple[int, ...])

sliderPosition: Tuple[int, ...]

This property holds the current slider positions. It is a tuple with length equal to the number of handles.

If tracking is enabled (the default), this is identical to value.

Access Functions:
range_slider.sliderPosition() -> Tuple[int, ...]
range_slider.setSliderPosition(val: Sequence[int]) -> None
Notifier Signal:
sliderMoved(Tuple[int, ...])

Additional properties

These options are in addition to the Qt QSlider API, and control the behavior of the bar between handles.

getter setter type default description
barIsVisible setBarIsVisible
hideBar / showBar
bool True Whether the bar between handles is visible.
barMovesAllHandles setBarMovesAllHandles bool True Whether clicking on the bar moves all handles or just the nearest
barIsRigid setBarIsRigid bool True Whether bar length is constant or "elastic" when dragging the bar beyond min/max.

Examples

These screenshots show QRangeSlider (multiple handles) next to the native QSlider (single handle). With no styles applied, QRangeSlider will match the native OS style of QSlider – with or without tick marks. When styles have been applied using Qt Style Sheets, then QRangeSlider will inherit any styles applied to QSlider (since it inherits from QSlider). If you'd like to style QRangeSlider differently than QSlider, then you can also target it directly in your style sheet. The one "special" property for QRangeSlider is qproperty-barColor, which sets the color of the bar between the handles.

The code for these example widgets is here

See style sheet used for this example
/*
Because QRangeSlider inherits from QSlider, it will also inherit styles
*/
QSlider {
    min-height: 20px;
}

QSlider::groove:horizontal {
    border: 0px;
    background: qlineargradient(x1:0, y1:0, x2:1, y2:1,
                                stop:0 #777, stop:1 #aaa);
    height: 20px;
    border-radius: 10px;
}

QSlider::handle {
    background: qradialgradient(cx:0, cy:0, radius: 1.2, fx:0.5,
                                fy:0.5, stop:0 #eef, stop:1 #000);
    height: 20px;
    width: 20px;
    border-radius: 10px;
}

/*
"QSlider::sub-page" is the one exception ...
(it styles the area to the left of the QSlider handle)
*/
QSlider::sub-page:horizontal {
    background: #447;
    border-top-left-radius: 10px;
    border-bottom-left-radius: 10px;
}

/*
for QRangeSlider: use "qproperty-barColor".  "sub-page" will not work.
*/
QRangeSlider {
    qproperty-barColor: #447;
}

macOS

Catalina

mac10

Big Sur

mac11

Windows

window

Linux

linux

Labeled Sliders

This package also includes two "labeled" slider variants. One for QRangeSlider, and one for the native QSlider:

QLabeledRangeSlider

labeled_range

from qtrangeslider import QLabeledRangeSlider

This has the same API as QRangeSlider with the following additional options:

handleLabelPosition/setHandleLabelPosition

Where/whether labels are shown adjacent to slider handles.

type: QLabeledRangeSlider.LabelPosition

default: LabelPosition.LabelsAbove

options:

  • LabelPosition.NoLabel (no labels shown adjacent to handles)
  • LabelPosition.LabelsAbove
  • LabelPosition.LabelsBelow
  • LabelPosition.LabelsRight (alias for LabelPosition.LabelsAbove)
  • LabelPosition.LabelsLeft (alias for LabelPosition.LabelsBelow)

edgeLabelMode/setEdgeLabelMode

type: QLabeledRangeSlider.EdgeLabelMode

default: EdgeLabelMode.LabelsAbove

options:

  • EdgeLabelMode.NoLabel: no labels shown at slider extremes
  • EdgeLabelMode.LabelIsRange: edge labels shown the min/max values
  • EdgeLabelMode.LabelIsValue: edge labels shown the slider range

fine tuning position of labels:

If you find that you need to fine tune the position of the handle labels:

  • QLabeledRangeSlider.label_shift_x: adjust horizontal label position
  • QLabeledRangeSlider.label_shift_y: adjust vertical label position

QLabeledSlider

labeled_range

from qtrangeslider import QLabeledSlider

(no additional options at this point)

Issues

If you encounter any problems, please file an issue along with a detailed description.

You might also like...
PyQt QGraphicsView with selection box. User can move vertical border of the box horizontally.

pyqt-horizontal-selection-square-graphics-view PyQt QGraphicsView with selection box. User can move vertical border of the box horizontally. Requireme

Osu statistics right on your desktop, made with pyqt
Osu statistics right on your desktop, made with pyqt

Osu!Stat Osu statistics right on your desktop, made with Qt5 Credits Would like to thank these creators for their projects and contributions. ppy, osu

基于百度的语音识别,用python实现,pyaudio+pyqt

Speech-recognition 基于百度的语音识别,python3.8(conda)+pyaudio+pyqt+baidu-aip 百度有面向python

Cricket game using PYQT
Cricket game using PYQT

Cricket-game-using-PYQT This is a Fantasy cricket Desktop application build in p

PyQt Custom Frameless Main Window (Enable to move and resize)

pyqt-custom-frameless-mainwindow PyQt Custom Frameless Main Window (Enable to move and resize) Requirements PyQt5 = 5.8 Setup pip3 install git+https:

Mini is a web browser application based on the Python PyQt web engine, made in 290 lines of code.
Mini is a web browser application based on the Python PyQt web engine, made in 290 lines of code.

Mini Mini is a web browser application based on the Python PyQt web engine, made in 290 lines of code. The code is written and published as is, so the

A simple browser for familiarity to PyQt :)
A simple browser for familiarity to PyQt :)

Erown_Browser a simple browser for familiarity to PyQt :) for start work with this install requirements by pip install -r requirements or you can use

A fast poisson image editing implementation that can utilize multi-core CPU or GPU to handle a high-resolution image input.
A fast poisson image editing implementation that can utilize multi-core CPU or GPU to handle a high-resolution image input.

Poisson Image Editing - A Parallel Implementation Jiayi Weng (jiayiwen), Zixu Chen (zixuc) Poisson Image Editing is a technique that can fuse two imag

Alt1-compatible widget host for RuneScape 3

RuneKit Alt1-compatible toolbox for RuneScape 3, for Linux and macOS. Compatibility macOS installation guide Running This project use Poetry as packag

Location field and widget for Django. It supports Google Maps, OpenStreetMap and Mapbox
Location field and widget for Django. It supports Google Maps, OpenStreetMap and Mapbox

django-location-field Let users pick locations using a map widget and store its latitude and longitude. Stable version: django-location-field==2.1.0 D

A better and faster multiple selection widget with suggestions
A better and faster multiple selection widget with suggestions

django-searchable-select A better and faster multiple selection widget with suggestions for Django This project is looking for maintainers! Please ope

Django model field that can hold a geoposition, and corresponding widget
Django model field that can hold a geoposition, and corresponding widget

django-geoposition A model field that can hold a geoposition (latitude/longitude), and corresponding admin/form widget. Prerequisites Starting with ve

Location field and widget for Django. It supports Google Maps, OpenStreetMap and Mapbox
Location field and widget for Django. It supports Google Maps, OpenStreetMap and Mapbox

django-location-field Let users pick locations using a map widget and store its latitude and longitude. Stable version: django-location-field==2.1.0 D

FrostedGlass is a translucent frosted glass effect widget, that creates a context with the background behind it.
FrostedGlass is a translucent frosted glass effect widget, that creates a context with the background behind it.

FrostedGlass FrostedGlass is a translucent frosted glass effect widget, that creates a context with the background behind it. The effect is drawn on t

A GUI widget for Linux to show current time in different timezones.
A GUI widget for Linux to show current time in different timezones.

A GUI widget to show current time in different timezones (under development). To use this widget: Run scripts/startup.py Select a country. A list of t

A Windows Dock Widget Written In Pure Python
A Windows Dock Widget Written In Pure Python

VEПUS A Windows Dock Widget Written In Pure Python What is Venus? Venus is a Dock Widget for your desktops interface. It adds a couple of really cool

A small bot to interact with the reddit API. Get top viewers and update the sidebar widget.

LiveStream_Reddit_Bot Get top twitch and facebook stream viewers for a game and update the sidebar widget and old reddit sidebar to show your communit

Gaphas is the diagramming widget library for Python.
Gaphas is the diagramming widget library for Python.

Gaphas Gaphas is the diagramming widget library for Python. Gaphas is a library that provides the user interface component (widget) for drawing diagra

A clock widget for linux ez to use no need for cmd line ;)

A clock widget in LINUX A clock widget for linux ez to use no need for cmd line ;) How to install? oh its ez just go to realese! what are the paltform

Comments
  • Must construct a QApplication before a QWidget with PySide6

    Must construct a QApplication before a QWidget with PySide6

    Describe the bug Everytime I try to instantiate a QRangeSlider I get a QWidget: Must construct a QApplication before a QWidget

    To Reproduce

    import sys
    
    from PySide6 import QtCore, QtWidgets, QtGui
    from qtrangeslider import QRangeSlider
    from qtrangeslider.qtcompat.QtCore import Qt as compactQt
    
    app = QtWidgets.QApplication(sys.argv)
    widget = QRangeSlider(compactQt.Horizontal)
    widget.show()
    

    Expected behavior QApplication is created so this work, right ? Also QRangeSlider doesn't accept Qt.Horizontal if I use PySide6.QtGui.Qt.

    Screenshots N/A

    Desktop (please complete the following information):

    • OS with version : Manjaro
    • Qt Backend : PySide6
    • Python version : 3.9.5

    Let me know if more information is needed to slove this.

    opened by seifane 6
  • QLabeledRangeSlider does not support methods using the bar

    QLabeledRangeSlider does not support methods using the bar

    QLabeledRangeSlider does not seem to support methods using the bar, while there is a bar present. Feature request: support bar methods such as setBarIsVisible, setBarMovesAllHandles and setBarIsRigid.

    Code: a = QLabeledRangeSlider() a.hideBar() Traceback (most recent call last): File "", line 1, in a.hideBar() AttributeError: 'QLabeledRangeSlider' object has no attribute 'hideBar'

    Amazing package by the way!

    opened by TheZappie 2
  • Generic slider

    Generic slider

    I keep running into annoying edge cases with the "classic" float slider approach that scales the values to some integer space for Qt. I have been using a generic slider model for QtRangeSlider, but this PR takes that pattern and uses it more generally for the FloatSlider (and QtRangeSlider is now just a variant of the _GenericSlider that accepts value of a sequence of scalars... one for each handle).

    It looks like tremendous overkill (and it may be?) ... but it's the only way I've been able to achieve all of the test cases I want to

    closes #13

    opened by tlambert03 1
Releases(v0.1.3)
Owner
Talley Lambert
Microscopist at Harvard Medical School
Talley Lambert
ZFS Administration GUI

ZYGGY ZFS Administration GUI Zyggy is a very simple GUI for basic ZFS administration. The system provides graphical access for most frequently used ZF

51 Dec 18, 2022
Dear PyGui: A fast and powerful Graphical User Interface Toolkit for Python with minimal dependencies

(This library is available under a free and permissive license however, if you Enjoy Dear PyGui please consider becoming a Sponsor) Dear PyGui is a si

Jonathan Hoffstadt 9.4k Jan 04, 2023
Windows & Linux GUI application to use a Satodime (satodime.io)

Satodime-Tool Licence: LGPL v3 Author: Toporin Language: Python (= 3.6) Homepage: https://github.com/Toporin/Satodime-Tool Introduction What is Satod

4 Dec 16, 2022
This simple python program can be used to make FontChooser dialog in Tkinter Applications.

tkFontBox This simple python program can be used to make FontChooser dialog in Tkinter Applications. how to use? Copy the tkFontBox.py file into your

Pawan Kumar Prachi 1 Feb 08, 2022
This is a GUI based text and image messenger. Other functionalities will be added soon.

Pigeon-Messenger (Requires Python and Kivy) Pigeon is a GUI based text and image messenger using Kivy and Python. Currently the layout is built. Funct

4 Jan 21, 2022
A simple fusee-launcher frontend for macOS

A simple fusee-launcher frontend for macOS (Universal). Supports macOS = 10.9. It has libusb statically linked, so you don't need to install anything

rob 25 Dec 19, 2022
A Url Shortener with GUI made in Python.

Url-Shortener-with-GUI-in-python A Url Shortener with GUI made in Python. To Run this download the zip file and run the main file or Clone this repo.

SidTheMiner 1 Nov 12, 2021
LyricsGenerator - A simple GUI made using Python(Tkinter) for generating song lyrics

Lyrics Generator Reference :- https://www.geeksforgeeks.org/create-a-gui-to-extr

Somya Ranjan Sahu 3 Mar 25, 2022
Custom Widgets For PyQt5

pyqtCuWi Custom Widgets Icon Button Documentation Rank Widget Documentation PopUp OuterRadius PopUp Documentation OuterRadius Documentation Producer:

.CODE 0 Apr 04, 2022
A Windows Dock Widget Written In Pure Python

VEПUS A Windows Dock Widget Written In Pure Python What is Venus? Venus is a Dock Widget for your desktops interface. It adds a couple of really cool

Secrets 18 Dec 30, 2022
OpenPort scanner GUI tool (CNMAP)

CNMAP-GUI- OpenPort scanner GUI tool (CNMAP) as you know it is the advanced tool to find open port, firewalls and we also added here heartbleed scanni

9 Mar 05, 2022
Awesome examples for my Sun Valley ttk theme!

Sun Valley ttk theme examples This is the examples repo for my stunning Sun Valley ttk theme! Be sure to start and atch this repo, because I will uplo

rdbende 117 Jan 03, 2023
Function-Plotter - GUI Application to plot math Functions

Function Plotter GUI Application to plot a user given function How to run instal

1 May 05, 2022
GUIOfTemperatureConverterUsingPython - GUI Of Temperature Converter Using Python

Fahrenheit To Celcius GUI Of Temperature Converter Below Video is the Output Of

SUJITHA RASAMSETTY 0 Mar 06, 2022
A simple Python Module for sending cross-platform desktop notifications on Windows, macOS and Linux

notify.py Cross platform desktop notifications for Python scripts and applications. Docs You can read the docs on this Git's Wiki, or here Supported P

Mustafa 178 Dec 26, 2022
Advanced GUI Discord Account Nuker that is easy to use, with many features.

AccountNukeV3 Showcase Youtube: Features: Remove all friends Block all friends Leave all servers Mass create servers Close all dms Mass dm Fuck Settin

Lodi#0001 24 May 22, 2022
A Virtual Desktop Assistant Written in Python

DesktopAssitant A Virtual Desktop Assistant Written in Python. It's generally a basic virtual assistant The basic purpose of this is to make work easi

Technerd Brainiac 597 Dec 31, 2022
A Python Tkinter based Inventory managment System

Inventory Management System Using Python Tkinter Introduction Inventory managemrnt system is an open source platform for manage business. It has a com

Amit Kumar Datta 2 Oct 14, 2021
Management Gui for OpenVR FSR PlugIn

OpenVR FSR App Small GUI to install/uninstall, tweak settings of the Modified OpenVR DLL with AMD FidelityFX SuperResolution Upscaler with a single cl

Stefan Tapper 234 Dec 20, 2022
Example GUI for Command line capable machine learning programs

Example GUI for Command line capable machine learning programs This is an example GUI made in PysimpleGUI and Tkinter, mainly for machine learning pro

Kim Yongwook 4 May 31, 2022