PDA

View Full Version : QScrollArea's Scroll Bars



ToddAtWSU
18th September 2006, 15:26
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!

wysota
18th September 2006, 15:39
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).

high_flyer
18th September 2006, 15:46
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.

munna
18th September 2006, 15:51
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

high_flyer
18th September 2006, 16:13
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.

ToddAtWSU
19th September 2006, 14:27
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 (http://doc.trolltech.com/4.1/qabstractslider.html#pageStep-prop) 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!! :)