Results 1 to 7 of 7

Thread: QSlider: Increase handle size -> How ?

  1. #1
    Join Date
    Sep 2010
    Location
    Hamburg, Germany
    Posts
    3
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default QSlider: Increase handle size -> How ?

    Hi,

    i am designing a GUI for a touchscreen device (Plastique Style). So far everything is fine, except that it is very difficult to hit the slider handle, because it is way to small. Therefore i would like to increase the size of my slider handle.

    My first try was to implement a style sheet for my vertical slider, like this one:
    Qt Code:
    1. /* slider_pwm1 is the name of my slider */
    2. #slider_pwm1::handle:vertical {
    3. min-width: 50px;
    4. width: 50px;
    5. }
    To copy to clipboard, switch view to plain text mode 
    ...but no success...

    My second guess was to override the PixelMetric function:
    Qt Code:
    1. // Override style for better Touchscreen handling
    2. class MyProxyStyle : public QProxyStyle
    3. {
    4. public:
    5. int pixelMetric ( PixelMetric metric, const QStyleOption * option = 0, const QWidget * widget = 0 ) const
    6. {
    7. switch(metric) {
    8. case PM_SliderControlThickness : return 50;
    9. default : return (QProxyStyle::pixelMetric(metric,option,widget));
    10. }
    11. }
    12. };
    13.  
    14. int main(int argc, char *argv[])
    15. {
    16. QApplication app(argc, argv);
    17. QApplication::setStyle(new MyProxyStyle);
    18. ...
    19. }
    To copy to clipboard, switch view to plain text mode 
    And again i had no success...

    Now i am running out of ideas... Does anybody out there has a clue/hint/link to solve this problem ?

    Thank you for your help !

    Arne

  2. #2
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    507
    Thanks
    11
    Thanked 76 Times in 74 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QSlider: Increase handle size -> How ?

    Hi, have you tried to use the "height" property in your style sheet instead of width?

    Ginsengelf

  3. #3
    Join Date
    Sep 2010
    Location
    Hamburg, Germany
    Posts
    3
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: QSlider: Increase handle size -> How ?

    Yes, i have tried all combinations (min-width, width, min-height, height), but it had no visible effect.
    But i am sure, that i address the style sheet correctly, because if i apply the following code from an Qt example...
    Qt Code:
    1. #slider_pwm1:vertical {
    2. border: 1px solid grey;
    3. width: 50px;
    4. margin: 22px 0 22px 0;
    5. }
    To copy to clipboard, switch view to plain text mode 
    ...it draws a box around my slider.
    I have already spent a lot of time searching for a solution, but i haven't found anything...
    Therefore any help is really appreciated

  4. #4
    Join Date
    Sep 2010
    Location
    Hamburg, Germany
    Posts
    3
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: QSlider: Increase handle size -> How ?

    Ok, white flag....
    I have given up to increase the size of the slider handle, but instead i am using a QDial widget. This works very well with touchscreens.

  5. #5
    Join Date
    May 2011
    Location
    near munich
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSlider: Increase handle size -> How ?

    Quote Originally Posted by ArneBurghardt View Post
    Qt Code:
    1. // Override style for better Touchscreen handling
    2. class MyProxyStyle : public QProxyStyle
    3. {
    4. public:
    5. int pixelMetric ( PixelMetric metric, const QStyleOption * option = 0, const QWidget * widget = 0 ) const
    6. {
    7. switch(metric) {
    8. case PM_SliderControlThickness : return 50;
    9. default : return (QProxyStyle::pixelMetric(metric,option,widget));
    10. }
    11. }
    12. };
    To copy to clipboard, switch view to plain text mode 
    If someone is still looking for a solution:
    use PM_SliderLength, not PM_SliderControlThickness (and I used QWindowsStyle, not QProxyStyle, but that doesn´t matter I guess)

  6. #6
    Join Date
    Jul 2015
    Posts
    52
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QSlider: Increase handle size -> How ?

    I am looking for a solution. Is it possible to do it with stylesheets?

  7. #7
    Join Date
    Aug 2016
    Posts
    1
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Cool Re: QSlider: Increase handle size -> How ?

    Quote Originally Posted by quimnuss View Post
    I am looking for a solution. Is it possible to do it with stylesheets?
    I finally worked it out. Counterintuitively, you need to mess with the groove, not the handle.

    Qt Code:
    1. /* First, you'll need to do this, to make room for the bigger handles. */
    2. QSlider:horizontal {
    3. min-height: 32px;
    4. }
    5.  
    6. QSlider::groove:horizontal {
    7. margin: -2px 0; /* decrease this size (make it more negative)—I changed mine from –2px to –8px. */
    8. }
    To copy to clipboard, switch view to plain text mode 
    (Apologies for the syntax highlighting—there doesn't seem to be a way to tell BBCode to highlight for CSS. I guess 'Qt code' means C?)

    Note that I'm working with horizontal sliders. If you're working with vertical sliders, you'll need to change 'horizontal' to 'vertical' in two places, and change the second argument (left/right) for the horizontal margin, not the first (top/bottom).

Similar Threads

  1. Replies: 3
    Last Post: 4th September 2009, 12:49
  2. How to increase font size in arm target
    By soumya in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 2nd September 2009, 05:58
  3. How to put custom handle image in QSlider using code?
    By montylee in forum Qt Programming
    Replies: 6
    Last Post: 29th January 2009, 19:38
  4. Increase the size of radio buttons
    By arunvv in forum Qt Programming
    Replies: 7
    Last Post: 24th January 2009, 00:09
  5. QSlider custom handle image not displayed
    By planglois in forum Qt Programming
    Replies: 1
    Last Post: 5th September 2008, 13:49

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.