Results 1 to 9 of 9

Thread: Hide a slider on a QScrollBar

  1. #1
    Join Date
    Oct 2009
    Posts
    70

    Default Hide a slider on a QScrollBar

    Hi...

    I've a scroll bar to view a certain numbers of widgets...

    but it's possible that the widgets are few and I don't need to scroll...for this I want to hide the slider on a QScrollBar...whitout hide all the QScrollBar...


    is it possible??

    Thanks

  2. #2
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Hide a slider on a QScrollBar

    You need to set the Qt::ScrollBarPolicy property to Qt::ScrollBarAsNeeded value.

  3. #3
    Join Date
    Oct 2009
    Posts
    70

    Default Re: Hide a slider on a QScrollBar

    No...I don't want to hide the whole scroll bar....

    I need to hide only the SLIDER under certain conditions!

    Is it possible?!

  4. #4
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Hide a slider on a QScrollBar

    Oops.
    Ok, that could be done, you need to subclass QscrollBar and need to hide the Slider manually. Checking the size of viewport with scroll area in paint event will do the trick. The main thing is to find out the point where you want to hide slider. But hiding the slider is just a function call.

  5. #5
    Join Date
    Oct 2009
    Posts
    70

    Default Re: Hide a slider on a QScrollBar

    Yes...I can call the hide() function of the slider...

    but there aren't any functions (nether on the QScrollBar ot the QAbstractSlider class) to get the pointer of the slider widget...

    how can I do this?!

  6. #6
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Hide a slider on a QScrollBar

    Gotcha !
    Now you left with 3 more options.
    1. Use QStyle and hide the sub control QStyle::SC_ScrollBarSlider.
    2. Use StyleSheet and hide the handle, something like this:
    QScrollBar::handle:horizontal {
    width: 0px;
    height: 0px;
    }
    3. Subclass QScrollBar and stop the painting of slider.

    StyleSheet option is easiest.

  7. #7
    Join Date
    Oct 2009
    Posts
    70

    Default Re: Hide a slider on a QScrollBar

    Thanks for your solution!!!

    I've solved with another solution:

    setEnable(false)

    when I doesn't need the slider.

    I thought about more solution but the simplest is often the best!!

  8. #8
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Hide a slider on a QScrollBar

    Doesn't it looks ugly, a disabled scroll bar? Then why don't you better hide it?

  9. #9
    Join Date
    Oct 2009
    Posts
    70

    Default Re: Hide a slider on a QScrollBar

    Doesn't it looks ugly, a disabled scroll bar? Then why don't you better hide it?
    I've used the setStylesSheet to make my custom scrollBar.

    After, in this class, I've a method like this:

    Qt Code:
    1. void MPScrollBar::setSlider(int iPageStep)
    2. {
    3. if(iPageStep==0)
    4. {
    5. setEnabled(false);
    6. }
    7. else
    8. {
    9. setEnabled(true);
    10. setPageStep(iPageStep);
    11. setSingleStep(pageStep());
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 

    to disable the scrollbar when the argument is 0.

    I can tell you sincerely that when I disable the scrollbar it doesn't look ugly...

Similar Threads

  1. linking a slider to a global variable
    By switch in forum Newbie
    Replies: 6
    Last Post: 5th August 2009, 08:02
  2. QScrollBar arrow display
    By sgg245 in forum Qt Programming
    Replies: 2
    Last Post: 16th February 2009, 06:57
  3. how to hide slider bar on the QScrollBar
    By yxmaomao in forum Qt Programming
    Replies: 7
    Last Post: 30th May 2008, 09:02
  4. get slider value
    By eric in forum Qt Programming
    Replies: 1
    Last Post: 8th November 2007, 19:47
  5. Custom (pixmap) slider handle for QScrollBar
    By Antrax in forum Qt Programming
    Replies: 1
    Last Post: 17th October 2006, 11:04

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.