Results 1 to 7 of 7

Thread: QSlider - how to color the space

  1. #1
    Join Date
    Apr 2010
    Posts
    48
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default QSlider - how to color the space

    Dear developers...

    i need to design my QSlider ...

    I have start point and end point on the slider bar

    the start point and the end point is movable by the user

    now i need to color the space between the start point and the end point

    Please let me know your helps and suggestion on this
    Last edited by newb; 20th July 2010 at 09:19.

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: QSlider

    Is your question on how to color the space?

  3. #3
    Join Date
    Apr 2010
    Posts
    48
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSlider

    . ..
    Last edited by newb; 20th July 2010 at 09:25.

  4. #4
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: QSlider

    This is highly theme specific as the look of the slider can change a lot between styles.

    However, the easiest way to do this outside of theming is to subclass the QSlider and reimplement the paint function. Draw the slider first, then on top of that draw a rectangle of custom size with custom color.

    Edit, but you'll loose the slider handle behind that rectangle.
    Maybe it's better to paint it underneath the slider.

    Anyway, the best way to do this is in the style itself or create a slider from scratch (reimplement the complete paint function)

  5. #5
    Join Date
    Apr 2010
    Posts
    48
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSlider

    thank you for the reply...if i try using with styles how can i go with...

  6. #6
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: QSlider

    I guess you have a custom widget (a subclassed QSlider) ?

    If so, create a QStyle subclass based on the style you normally use. Then implement the painting of your custom widget, based on a regular QSlider.
    But, before you paint the items that need to be on top (like the slider handle) and after you paint the items that need to be underneath, paint the colored space.

    Something like this:
    1. paint the borders and background
    2. paint the colored space
    3. paint the handle

    Step 2 would be missing in a regular QSlider.
    If you just reimplement the paint function like I said earlier, you can't paint in the middle, only at the beginning (underneath) or at the end (on top)

  7. #7
    Join Date
    Feb 2010
    Posts
    99
    Thanks
    31
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QSlider

    Just skimming through you quesiton I am wondering if you could use stylesheet.
    More info @ QSlider Stylesheet

Similar Threads

  1. QSlider
    By mickey in forum Qt Programming
    Replies: 5
    Last Post: 27th November 2009, 17:21
  2. Help Qslider
    By superteny in forum Qt Programming
    Replies: 5
    Last Post: 9th July 2009, 10:03
  3. QSlider tickInterval
    By yogeshgokul in forum Qt Programming
    Replies: 3
    Last Post: 16th September 2008, 11:29
  4. QSlider
    By merry in forum Qt Programming
    Replies: 22
    Last Post: 27th June 2007, 07:42
  5. QSlider
    By ToddAtWSU in forum Qt Programming
    Replies: 3
    Last Post: 10th May 2006, 16:41

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.