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
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:

Jung Gyu Yoon 1 Jan 13, 2022
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

Dmitry Karpenko 6 Nov 7, 2022
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

Ehsan Amirahmadi 9 May 18, 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
UberGui is a lightweight multi-threaded, webRender UI module for TouchDesigner

UberGui V4 UberGui is a lightweight multi-threaded, webRender UI module for TouchDesigner projects. The aim is to solve the trifecta of challenges bui

LUCAS M MORGAN 48 Nov 20, 2022
A GUI panel to manage multi monitor on i3wm.

Monitor manager Only for I3wm (Just for now) It's about two years that I'm using i3 as my window manager and in my experience this window manager allo

Wire.Nemo 3 Nov 6, 2021
Kivy is an open source Python framework for creating cross-platform multi-touch mobile applications with Natural User Interface.

Kivy is an open source Python framework for creating cross-platform multi-touch mobile applications with Natural User Interface.

Grace Ugochi Nneji 3 Feb 15, 2022
Image comparison slider component for Streamlit

Streamlit Image Comparison Component A simple Streamlit Component to compare images with a slider in Streamlit apps using Knightlab's JuxtaposeJS. It

fatih 109 Dec 23, 2022
Create rangebased on lists or values of the range itself. Range any type. Can you imagine?

funcao-allrange-for-python3 Create rangebased on lists or values of the range itself. Range any type. Can you imagine? WARNING!!! THIS MODULE DID NOT

farioso-fernando 1 Feb 9, 2022
This repository contains code for a youtube-dl GUI written in PyQt.

youtube-dl-GUI This repository contains code for a youtube-dl GUI written in PyQt. It is based on youtube-dl which is a Video downloading script maint

M.Yasoob Ullah Khalid ☺ 191 Jan 2, 2023