Results 1 to 3 of 3

Thread: Dynamic label to right of slider resizes slider

  1. #1
    Join Date
    Apr 2010
    Posts
    18
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Dynamic label to right of slider resizes slider

    Hi all

    I have a dumb question, but this doing my head in (as layouts generally do). I'm pretty sure the solution is straight forward, I'm just not seeing it.

    Anyway, I have a dialog with three horizontal sliders (they are actually custom sliders, but I don't think it is relevant). Each slider is for picking a color value from 0-255 (for red, green and blue respectively). To the right of each slider I have a label to display its value. The sliders have a horizontal size policy of expanding so that when the dialog is resized horizontally so are the sliders. The problem is when the value in a label changes between 1, 2 and 3 characters in length it affects the length of the slider. I wish the sliders to remain unchanged in length when the label value changes.

    I was thinking that I need a minimum size for the label that can hold three characters, but I don't think this will take into consideration variations in font size?

    The sliders also each have a label to their left, R, G and B, respectively. I currently have the labels and the sliders in a grid layout.

    Thanks for reading.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Dynamic label to right of slider resizes slider

    What you could do is create a QLabel Subclass and reimplement sizeHint() or minimumSizeHint() such that is uses QFontMetrics of the current font to determine the length of three digits.

    Cheers,
    _

  3. #3
    Join Date
    Apr 2010
    Posts
    18
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Dynamic label to right of slider resizes slider

    That's a good idea, I will try that. Thanks.


    Added after 25 minutes:


    Yeah, that worked. So easy. Thanks! I'm a bit out of practice with Qt but it's coming back to me now.
    Last edited by zenzero-2001; 3rd October 2013 at 10:37.

Similar Threads

  1. Does Qt have slider with 2 handles
    By ainne810329 in forum Qt Programming
    Replies: 2
    Last Post: 6th February 2013, 11:46
  2. Replies: 0
    Last Post: 2nd August 2010, 11:17
  3. help on my slider
    By newb in forum Qt Programming
    Replies: 1
    Last Post: 13th July 2010, 15:36
  4. Replies: 2
    Last Post: 21st March 2010, 09:01
  5. get slider value
    By eric in forum Qt Programming
    Replies: 1
    Last Post: 8th November 2007, 19:47

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.