Updating QScrollArea scroll bars in code - verticalScrollBar()->value() always returns 0 whatever value it is given
-
I have a test app with a QScrollArea which is nicely using verticalScrollBar()->setValue() to scroll up and down the scroll bars.
Created a CScrollArea (until I think of a better name) inherited from QScrollArea. Call:
@verticalScrollBar()->setValue(m_verticalScroll);
m_verticalScroll = verticalScrollBar()->value();@no matter what the value of m_verticalScroll, verticalScrollBar()->value() returns 0 - i.e. nothing moves.
Note: My CScrollArea is the centralWidget in a MainWindow (but the QScrollArea within the test app is also the central widget).
Any thoughts please?
-
your question is too brief and you need to provide more details. Scrolling is straightfoward in QT unlike win32 api/MFC where honestly I found it a pain... Here is a short program where i scroll to
the bottom of a page.
"Download test project":https://dl.dropbox.com/u/51343591/CScroll.rar
@ int maximumY= scrollarea->verticalScrollBar()->maximum();
scrollarea->verticalScrollBar()->setValue(maximumY);@And slam dunk no questions asked, you scroll to the bottom.
"see image":http://i.imgur.com/SpXwL.jpg -
Appreciate the response. As I say, I have the code working in my test app, but the same code (from the same source file) just does not work. If I had more information I would put give it but I do not - it is not even worth including my code in my main project because it is all commented out while I get this working. I am literally just calling the same thing, in the same solution with a different project - very frustrating with such a simple bit of code.
-
OK, with a fresh brain I have now solved it (just in case anyone else has this problem). The projects were identical for all intents and purposes except for the ui (since I was not accessing the ui and my scroll class was the only thing on the screen I did not see that as a problem).
My full project had styling applied in the UI - inc styling on the scroll bar. Remove that and bingo!!!
(In my defence the whole point was to have the scroll bars hidden so I did not see the styling).