Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Updating QScrollArea scroll bars in code - verticalScrollBar()->value() always returns 0 whatever value it is given
QtWS25 Last Chance

Updating QScrollArea scroll bars in code - verticalScrollBar()->value() always returns 0 whatever value it is given

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 5.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dolphin
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • T Offline
      T Offline
      trueleowdeo
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • D Offline
        D Offline
        Dolphin
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • D Offline
          D Offline
          Dolphin
          wrote on last edited by
          #4

          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).

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved