Results 1 to 5 of 5

Thread: slider handle not centered on tickmarks

  1. #1
    Join Date
    Oct 2014
    Posts
    104
    Thanks
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default slider handle not centered on tickmarks

    Did any one of you encountered this problem?

    The Slider handle isn't centered on the tickmarks, it only displays correctly at the minimum and maximum value.

    here's my code

    Qt Code:
    1. Slider {
    2. id: slider
    3. anchors {
    4. fill: parent
    5. topMargin: 30
    6. horizontalCenter: parent.horizontalCenter
    7. }
    8. style: SliderStyle {
    9. groove: Rectangle {
    10. color: "white"
    11. implicitHeight: 8
    12. implicitWidth: parent.width
    13. radius: 6
    14. gradient: Gradient {
    15. GradientStop { position: 0.0; color: "gray" }
    16. GradientStop { position: 1.0; color: "white" }
    17. }
    18. }
    19. handle: Image {
    20. source: "../../images/mdpi/handle-slider.png"
    21. sourceSize.width: 30
    22. sourceSize.height: 30
    23. anchors {
    24. centerIn: parent.Center
    25. }
    26. }
    27. tickmarks: tickMarks
    28.  
    29. Component {
    30. id: tickMarks
    31. Repeater {
    32. id: repeater
    33. model: control.stepSize > 0 ? 1 + (control.maximumValue - control.minimumValue) / control.stepSize : 0
    34. Rectangle {
    35. color: "gray"
    36. width: 2
    37. height: (index % 2 == 0) ? 14 : 8
    38. y: repeater.height
    39. x: styleData.handleWidth / 2 + index * ((repeater.width - styleData.handleWidth) / (repeater.count-1))
    40. }
    41. }
    42. }
    43. }
    44. maximumValue: 80
    45. minimumValue: 1
    46. stepSize: 10
    47. tickmarksEnabled: true
    48. value: 40
    49. }
    To copy to clipboard, switch view to plain text mode 

    slider.PNG

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: slider handle not centered on tickmarks

    Are you sure the tick marks are positioned correctly?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Oct 2014
    Posts
    104
    Thanks
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: slider handle not centered on tickmarks

    Quote Originally Posted by wysota View Post
    Are you sure the tick marks are positioned correctly?
    Yes. When I used these lines of codes only it works perfectly.

    Qt Code:
    1. Slider {
    2. id: slider
    3. anchors {
    4. fill: parent
    5. topMargin: 30
    6. horizontalCenter: parent.horizontalCenter
    7. }
    8. maximumValue: 80
    9. minimumValue: 1
    10. stepSize: 10
    11. tickmarksEnabled: true
    12. value: 40
    13. }
    To copy to clipboard, switch view to plain text mode 

    However after adding the style property with SliderStyle component, the problem occurs.

    Qt Code:
    1. Slider {
    2. id: slider
    3. anchors {
    4. fill: parent
    5. topMargin: 30
    6. horizontalCenter: parent.horizontalCenter
    7. }
    8. style: SliderStyle {
    9. groove: Rectangle {
    10. color: "white"
    11. implicitHeight: 8
    12. implicitWidth: parent.width
    13. radius: 6
    14. }
    15. }
    16. maximumValue: 80
    17. minimumValue: 1
    18. stepSize: 10
    19. tickmarksEnabled: true
    20. value: 40
    21. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Oct 2014
    Posts
    104
    Thanks
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: slider handle not centered on tickmarks

    After doing some changes on the code, it seems that once the style property is overridden, the problem occurred if the implicitwidth property increases.
    When the implicitWidth is from 200 or more, you will notice that the handle isn't centered in some tickmarks anymore.
    However if without style, the default handle is always centered into tickmarks.

    Any work around on this one?
    Last edited by joko; 27th October 2014 at 17:10.

  5. #5
    Join Date
    Oct 2014
    Posts
    104
    Thanks
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: slider handle not centered on tickmarks

    I managed to resolved the issue, by changing the minimumValue from 1 to 0 and in tickmarks component, i subtracted the Rectangle width from the repeater.width.

Similar Threads

  1. QSlider how to check if slider handle is selected
    By hel in forum Qt Programming
    Replies: 3
    Last Post: 15th May 2014, 09:52
  2. drawPoint not centered
    By Alundra in forum Qt Programming
    Replies: 1
    Last Post: 3rd November 2013, 08:38
  3. Dynamic label to right of slider resizes slider
    By zenzero-2001 in forum Qt Programming
    Replies: 2
    Last Post: 3rd October 2013, 11:11
  4. Replies: 2
    Last Post: 21st March 2010, 10:01
  5. Custom (pixmap) slider handle for QScrollBar
    By Antrax in forum Qt Programming
    Replies: 1
    Last Post: 17th October 2006, 12:04

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.