superqt icon indicating copy to clipboard operation
superqt copied to clipboard

QLabeledRangeSlider no labels after setValue() int the second time

Open looninho opened this issue 3 years ago • 2 comments

update values the second time removes all labels When I create my_slider QLabeledRangeSlider object then set the values with my_slider.setValue(mylist_1) every thing works fine but when I set a new dataset with my_slider.setValue(mylist_2), only handles updated all labels disappear.

To Reproduce Steps to reproduce the behavior:

  1. create a QWidget to host the QLabeledRangeSlider slider
  2. create a QLabeledRangeSlider object as child then set its value with .setValue() method
  3. create a QPushButton to set new values then connect its signal clicked to an update method
  4. see error: the slider updates with no label at each handle, only range label displayed.

example code

import sys, os

from PySide6.QtWidgets import QApplication, QWidget, QPushButton
from PySide6.QtCore import Qt
from superqt import QLabeledRangeSlider

class Window(QWidget):
  def __init__(self, parent=None):
    super(Window, self).__init__(parent)
    sl = tuple([0, 90, 210, 259, 374])

    self.main_slider = QLabeledRangeSlider(parent=self)
    self.main_slider.setOrientation(Qt.Horizontal)
    width = self.geometry().width()
    self.main_slider.setMinimumWidth(width)

    self.main_slider.setRange(sl[0], sl[-1])
    self.main_slider.setValue(tuple(sl))

    btn = QPushButton(self)

    btn.clicked.connect(self.update)


  def update(self):
    sl = tuple([1261, 1281, 1334, 1365, 1697, 1871, 1916])
    self.main_slider.setRange(sl[0], sl[-1])
    self.main_slider.setValue(sl)


if __name__ == '__main__':
  app = QApplication([])
  win = Window()
  win.show()
  sys.exit(app.exec())

Expected behavior expected labels .at each handle.

Screenshots image image

Desktop (please complete the following information):

  • Windows 10
  • PySide6
  • Python 3.7.13, conda 4.10.1

looninho avatar Jun 20 '22 14:06 looninho

FOUND: one have to addd this line after setValue():

my_slider.setHandleLabelPosition(1)

looninho avatar Jun 20 '22 15:06 looninho

FOUND: one have to addd this line after setValue():

my_slider.setHandleLabelPosition(1)

That is a weired behavior. I would think this is a bug.

MosGeo avatar Jun 20 '22 16:06 MosGeo

sorry for the delay here... And thank you very much @looninho for the super useful example. This is fixed in #123

tlambert03 avatar Oct 03 '22 19:10 tlambert03