Results 1 to 6 of 6

Thread: QScrollArea's Scroll Bars

  1. #1
    Join Date
    Jan 2006
    Location
    Ohio
    Posts
    332
    Thanks
    37
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Red face QScrollArea's Scroll Bars

    I have a QScrollArea and I am having problems manipulating the scroll bars. Whenever I click on the scroll bar area that is not the actual scroll bar, the scroll bar moves down to the mouse click. I want the scroll bar to actually just jump down one page. Say the scroll bar is at the top and its length is about 1/8 of the window size, if I click at the bottom of the scroll bar area, I just want the bar to drop down to the 2/8 position instead of all the way to the bottom. Does this make sense what I want it to do? If so, how is this possible? I have looked through the documentation and I cannot figure out how to get the scroll bar work in this manner. Thanks!

  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: QScrollArea's Scroll Bars

    You can filter the mousePressEvent for the scrollbar and scroll the scroll area yourself in the filter. Some scroll area implementations might provide their own methods to scroll "one page down" (for example using QTextDocument for QTextEdit).

  3. #3
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QScrollArea's Scroll Bars

    You can use horizontalScrollBar() and verticalScrollBar() to access the scrollbars, and you can sent the scrollbars values to what ever you want with setValue().
    With maximum() and minimum() you can do a proportional scroll.

  4. #4
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QScrollArea's Scroll Bars

    Quote Originally Posted by high_flyer
    You can use horizontalScrollBar() and verticalScrollBar() to access the scrollbars, and you can sent the scrollbars values to what ever you want with setValue().
    With maximum() and minimum() you can do a proportional scroll.
    I don't think you can do that.

    QScrollBar * QAbstractScrollArea::verticalScrollBar () const

  5. #5
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QScrollArea's Scroll Bars

    Quote Originally Posted by munna View Post
    I don't think you can do that.

    QScrollBar * QAbstractScrollArea::verticalScrollBar () const
    From the docs:
    For example, you can set the QAbstractScrollArea::horizontalScrollBarPolicy and QAbstractScrollArea::verticalScrollBarPolicy properties. Or if you want the scroll bars to adjust dynamically when the contents of the scroll area changes, you can use the horizontalScrollBar() and verticalScrollBar() functions (which enable you to access the scroll bars) and set the scroll bars' values whenever the scroll area's contents change, using the QScrollBar::setValue() function.
    Besides, the const in this case only means that verticalScrollBar() it self makes no changes to any data, but it doesn't mean you can't change the data it delivers outside its scope.
    Last edited by high_flyer; 18th September 2006 at 16:20.

  6. #6
    Join Date
    Jan 2006
    Location
    Ohio
    Posts
    332
    Thanks
    37
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Cool Re: QScrollArea's Scroll Bars

    I think you are leading me in the right way high_flyer in retrieving the scroll bars. I have discovered the PageUp and PageDown buttons provide the functionality I want by performing a pageStep when either key is pressed. So if the slider is at the top and I press on the bottom, I want the slider to move one page down as if I were pressing the PageDown key. Is there a simple way to handle this, or will it require doing some mouse capturing like wysota talked about? I can do this if necessary but if there is a simpler way that would be great! Thanks again!!

Similar Threads

  1. Retrieving offsets of scroll in QWorkspace
    By hardgeus in forum Qt Programming
    Replies: 6
    Last Post: 9th May 2006, 03:25
  2. Replies: 6
    Last Post: 14th April 2006, 06:39
  3. Scroll View for Canvas
    By Kapil in forum Qt Programming
    Replies: 10
    Last Post: 25th March 2006, 08:19
  4. QRubberBand painting in the scroll area widget
    By SkripT in forum Qt Programming
    Replies: 7
    Last Post: 17th January 2006, 17:48

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.