Results 1 to 5 of 5

Thread: qslider fixed to tick marks

  1. #1
    Join Date
    Jan 2009
    Posts
    14
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default qslider fixed to tick marks

    Hi,

    I need that the Slider moves not to be continous, only from a tick to another ignoring the space (and therefore the values) between the 2 ticks.

    I see how create the ticks with setTickPosition() and setTickInterval(), but nothing to fix the slider handle to the ticks.

    Any idea?

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: qslider fixed to tick marks

    Qt Code:
    1. QSlider slider;
    2. slider.setTickInterval(1);
    3. slider.setRange(0,40); // where 40 is your "tick count"
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2009
    Posts
    14
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: qslider fixed to tick marks

    I see, so the movement from a tick to another always is 1 unit.

    For example, for a slider that only can take the values 0->25->50->75->100, I have to create a slider from 0->4 with tickInterval=1, and then multiply the value by 4.
    Qt Code:
    1. QSlider slider;
    2. slider.setTickInterval(1);
    3. slider.setRange(0,4);
    4. ...
    5. int nPercentVal = slider.value() * 4;
    To copy to clipboard, switch view to plain text mode 

    So, isn't a way to avoid that multiplication (setting range 0->100) but slider handle only moving through 5 ticks in the slider?

  4. #4
    Join Date
    Jan 2009
    Posts
    14
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: qslider fixed to tick marks

    Sorry... I mean
    Qt Code:
    1. int nPercentVal = slider.value() * 25;
    To copy to clipboard, switch view to plain text mode 


  5. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: qslider fixed to tick marks

    Well, I see no possibility for that. But you can easy subclass QSlider and change the value setter and getter function with a custom factor.

  6. The following user says thank you to Lykurg for this useful post:

    holst (24th July 2009)

Similar Threads

  1. QSlider with tick marks numbers
    By mastupristi in forum Qt Programming
    Replies: 3
    Last Post: 6th July 2009, 09:32
  2. QSlider with a custom set of labels for the tick marks?
    By whitefurrows in forum Qt Programming
    Replies: 3
    Last Post: 5th August 2007, 17:05

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.