Skip to content

QLabeledDoubleRangeSlider label width too small #335

@OwlSurojit

Description

@OwlSurojit

Describe the bug
The width calculation logic in SliderLabel appears to be not very robust for use withing QLabeledDoubleRangeSlider.
E.g. when setting the range using integer values, all label fields (min, max, and values) are cut off (see Example 1 below). When setting the range using floats, the label width is slightly bigger, but still not big enough, and importantly it doesn't scale properly when increasing the number of decimals (see Example 2).

To Reproduce
Example 1:

from PyQt5 import QtWidgets as QtW
from PyQt5.QtCore import Qt
from superqt import QLabeledDoubleRangeSlider

app = QtW.QApplication([])

slider = QLabeledDoubleRangeSlider(Qt.Orientation.Horizontal)
slider.setRange(-1, 1)
slider.setValue((-0.5, 0.5))
slider.show()

app.exec_()

Example 2:

from PyQt5 import QtWidgets as QtW
from PyQt5.QtCore import Qt
from superqt import QLabeledDoubleRangeSlider

app = QtW.QApplication([])

slider = QLabeledDoubleRangeSlider(Qt.Orientation.Horizontal)
slider.setRange(-1.0, 1.0)
slider.setDecimals(5)
slider.setValue((-0.5, 0.5))
slider.show()

app.exec_()

Expected behavior
The slider labels should grow to fit the entire value.

Screenshots
Example 1:
Image
The labels only show the numbers after the decimal point, but upon focusing them it is possible to scroll through to see they indeed contain the full value.

Example 2:
Image

Desktop:

  • OS: Windows 11 Version 10.0.26200 Build 26200
  • Qt Backend: PyQt5
  • Python version: 3.13.12

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions