Results 1 to 8 of 8

Thread: Slider with log ticks?

  1. #1
    Join Date
    Oct 2015
    Posts
    45
    Thanks
    8
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Slider with log ticks?

    I've done a lot of searching on the web and in this forum, so I'm guessing I have not used the right search terms (or I'm the first to want to do this...which would be a first for me to have an original idea ).

    I'm writing an audio oriented app in PyQt the normal scales for audio are log based.

    So, what I want to do is display a slider that has ticks in a log spacing along the slider (i.e. not linear, in this particular case it would be decibels).

    I have sliders and I already map the range of the slider to decibels for numerical display of the value, but have only figured out how to get ticks to be linear along the slider.

    Since I haven't found any examples or even (at least to me) hints as how to attempt this, any pointers to docs or ideas are much appreciated.

    Thanks,
    Mac

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Slider with log ticks?

    Assuming you are using QSlider based widget, it should be possible by overriding sliderChange() funciton
    Qt Code:
    1. void QAbstractSlider::sliderChange(SliderChange change)[virtual protected]
    To copy to clipboard, switch view to plain text mode 
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Oct 2015
    Posts
    45
    Thanks
    8
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Slider with log ticks?

    I am using QSlider.
    The doc for sliderChange say: "Reimplement this virtual function to track slider changes such as SliderRangeChange..."

    I don't see how this allows me to change the spacing of the ticks from linear to logarithmic. (It could my lack of understanding in general...but, I'm trying to learn.)

  4. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Slider with log ticks?

    It may not be trivial but you can monitor the change in the slider value and adjust it to match the log scale you want.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  5. #5
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,309
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Slider with log ticks?

    Qwt http://qwt.sf.net offers sliders with logarithmic scales - see the controls example. Python wrappers for a current version of Qwt6 can be found here https://github.com/GauiStori/PyQt-Qwt, for Qwt5 there is pyqwt.

    Uwe

  6. #6
    Join Date
    Oct 2015
    Posts
    45
    Thanks
    8
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Slider with log ticks?

    Thanks for the links to those scales and controls. I have a couple places in my code that those will come in handy.

    And thanks to others for other suggestions.

    As for my original question, I solved it with simple sub class of the slider paint:

    Qt Code:
    1. class MySlider(QtWidgets.QSlider):
    2. def __init__(self, parent=None):
    3. super(MySlider, self).__init__(parent)
    4.  
    5. def paintEvent(self, event):
    6. """Paint log scale ticks"""
    7. super(MySlider, self).paintEvent(event)
    8. qp = QPainter(self)
    9. pen = QPen()
    10. pen.setWidth(2)
    11. pen.setColor(Qt.black)
    12.  
    13. qp.setPen(pen)
    14. font = QFont('Times', 10)
    15. font_y_offset = font.pointSize()/2
    16. qp.setFont(font)
    17. size = self.size()
    18. contents = self.contentsRect()
    19. db_val_list = [10, 5, 0, -5, -10, -20, -30, -40, -50, -60, -90]
    20. for val in db_val_list:
    21. if val == 10:
    22. y_val_fudge = 12
    23. elif val == -90:
    24. y_val_fudge = -12
    25. db_scaled = db_to_int(val)
    26. y_val = contents.height() - translate(db_scaled, 0, 1023, 0, contents.height())
    27. if val == -90:
    28. qp.drawText(contents.x() - font.pointSize(), y_val + font_y_offset + y_val_fudge, '-oo')
    29. else:
    30. qp.drawText(contents.x() - font.pointSize(), y_val + font_y_offset + y_val_fudge,'{0:2}'.format(val))
    31. qp.drawLine(contents.x() + font.pointSize(), y_val + y_val_fudge, contents.x() + contents.width(), y_val + y_val_fudge)
    To copy to clipboard, switch view to plain text mode 

    It works, but after implementing it the GUI looked pretty bad with 30 sliders, side by side, with scales. Very cluttered.

  7. #7
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Slider with log ticks?

    It works, but after implementing it the GUI looked pretty bad with 30 sliders, side by side, with scales. Very cluttered.
    Yeah, but that's sort of like what a sound board looks like, right? Maybe you can vary the appearance by grouping sets of related sliders and giving them a common color for their slider handles, or putting them in group boxes with different background colors. It doesn't have to be garish.

    Or if all of the sliders don't have to be displayed at the same time, dividing them into groups on tabs, each tab controlling a specific set of functions.

    Or if all the scales are the same, turning off tick labels and/or ticks for all except the ones on the ends of the rows.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  8. #8
    Join Date
    Oct 2015
    Posts
    45
    Thanks
    8
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Slider with log ticks?

    Agreed, sound boards typically an intimidating array of knobs, buttons, indicators, and sliders.

    All of your ideas are possibilities. Once I get the core of the application fleshed out I'll probably take another look at the ticks and labels.

    As for the tab idea...I already have tabs for each mixer, so I'd have to have a tab widget in each mixers tab. Not sure how much layering becomes annoying and/or confusing.

    But that's the sort of things that need to be worked out with GUI design.

Similar Threads

  1. setting ticks on QwtPlotScaleItem
    By ericLemanissier in forum Qwt
    Replies: 5
    Last Post: 15th August 2014, 10:50
  2. Dynamic label to right of slider resizes slider
    By zenzero-2001 in forum Qt Programming
    Replies: 2
    Last Post: 3rd October 2013, 11:11
  3. Replies: 14
    Last Post: 30th October 2012, 16:45
  4. Lining up Inner and Outer Ticks
    By bigjoeystud in forum Qwt
    Replies: 3
    Last Post: 27th September 2012, 08:31
  5. Replies: 2
    Last Post: 21st March 2010, 10:01

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.