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. How to preserve QScrollArea scrollbar position when window is maximized and restored?
Forum Updated to NodeBB v4.3 + New Features

How to preserve QScrollArea scrollbar position when window is maximized and restored?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 106 Views 1 Watching
  • 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.
  • B Offline
    B Offline
    byrAlpha
    wrote last edited by
    #1

    Hi everyone,

    I have a window containing a QScrollArea. When I maximize the window and then restore it back to normal size, the scrollbars reset to the default position (usually top-left). I want to remember the scrollbar positions before maximizing and restore them after the window is restored.

    What I’ve tried so far:

    Saving the scrollbar values (horizontalScrollBar()->value() and verticalScrollBar()->value()) before maximizing.

    Restoring these values after the window is restored, using a delayed call with QTimer::singleShot to ensure layout is updated.

    However, I’m not sure if this is the best practice or if Qt provides a better official way to handle this, especially when the content inside the scroll area can dynamically change and layouts get refreshed.

    My questions are:

    How do you usually implement remembering and restoring scrollbar positions on window maximize/restore?

    Are there any Qt signals or events better suited for catching these state changes?

    What common pitfalls should I watch out for to make sure scrollbar restoration works reliably?

    Any advice, best practices, or code examples would be greatly appreciated!

    Thanks a lot!

    1 Reply Last reply
    0
    • Z Offline
      Z Offline
      Zbigniew-Sch
      wrote last edited by
      #2

      Hi,

      What type of "QWidget" are you using?
      Is that - "QMdiSubWindow" ?

      1 Reply Last reply
      0
      • B Offline
        B Offline
        byrAlpha
        wrote last edited by
        #3

        @Zbigniew-Sch use QScrollArea

        1 Reply Last reply
        0
        • Z Offline
          Z Offline
          Zbigniew-Sch
          wrote last edited by
          #4

          Use signal for parent of QScrollArea:
          windowStateChanged(Qt::WindowState windowState)
          and save/restore parameters for QScrollArea

          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