Skip to content

Styling QRangeSlider #292

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
iegorval opened this issue Apr 25, 2025 · 0 comments
Open

Styling QRangeSlider #292

iegorval opened this issue Apr 25, 2025 · 0 comments

Comments

@iegorval
Copy link

iegorval commented Apr 25, 2025

Hello,

I am struggling to apply my QSlider's style to QRangeSlider, and docs do not seem to go into too much detail about it.

Please see this example comparing QSlider with QRangeSlider:

from PySide6.QtWidgets import (
    QApplication,
    QWidget,
    QVBoxLayout,
    QSlider,
)
from PySide6.QtCore import Qt
from superqt import QRangeSlider

QSLIDER_QSS = """
QSlider::groove:horizontal {
    background: #F5F4F4;
    height: 6px;
    border-radius: 3px;
}
QSlider::sub-page:horizontal {
    background: #2390de;
    height: 6px;
    border-radius: 3px;
}
QSlider::add-page:horizontal {
    background: #DDEAED;
    height: 6px;
    border-radius: 3px;
}
QSlider::add-page:disabled:horizontal {
    background: rgb(150, 150, 150);
}
QSlider::sub-page:disabled:horizontal {
    background: rgb(150, 150, 150);
}
QSlider::handle:horizontal {
    background: white;
    border: 1px solid #555;
    width: 12px;
    height: 12px;
    margin: -4px 0;
    border-radius: 7px;
}
QSlider::handle:horizontal:hover {
    background: #DDDDDD;
}
QSlider::handle:horizontal:pressed {
    background: #DDEAED;
}
QSlider::handle:horizontal:disabled {
    background: rgb(150, 150, 150);
    border: 1px solid #8A8A8A;
    width: 12px;
    height: 12px;
    margin: -4px 0;
    border-radius: 7px;
    opacity: 0.5;
}

QRangeSlider {
    qproperty-barColor: #2390de;
}
"""


def main():
    app = QApplication([])

    window = QWidget()
    layout = QVBoxLayout(window)

    # Standard QSlider
    qslider = QSlider(Qt.Horizontal)
    qslider.setMinimum(0)
    qslider.setMaximum(100)
    qslider.setValue(50)
    qslider.setStyleSheet(QSLIDER_QSS)

    # QRangeSlider from SuperQt
    qrangeslider = QRangeSlider(Qt.Horizontal)
    qrangeslider.setMinimum(0)
    qrangeslider.setMaximum(100)
    qrangeslider.setValue((20, 80))
    qrangeslider.setStyleSheet(QSLIDER_QSS)

    layout.addWidget(qslider)
    layout.addWidget(qrangeslider)

    window.setWindowTitle("Styled QSlider + QRangeSlider")
    window.resize(400, 100)
    window.show()
    app.exec()


if __name__ == "__main__":
    main()

So, what happens is that somehow barColor is only seen as border and, moreover, some light-blue color is applied not between left and right handle, but instead from left handle to the right end of the whole slider... See also screenshot below. What is conflicting between the provided QSS and QRangeSlider from superqt?

I am on PySide6, Win11 and latest superqt version from PyPI.

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant