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 keep the currently visible content section of a scroll area in Qt?
Qt 6.11 is out! See what's new in the release blog

How to keep the currently visible content section of a scroll area in Qt?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 369 Views 2 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.
  • MaFloBraM Offline
    MaFloBraM Offline
    MaFloBra
    wrote on last edited by
    #1

    First of all: I know this is not the PySide2 sub forum, however, my question is not Python but Qt-related, so I guess I have more chances here in the general Qt forum... Now on to my question:

    In my Qt application I have a QScrollArea with a widget that uses a QVBoxLayout. The application continuously adds new images to the top of the scroll area. Now let's assume the user scrolls half way down the list of images, so that the vertical scroll bar is somewhere in the middle of the scroll area.

    Now a new image is being added to the scroll area. This does not alter the scroll bar. However, since the new image has been added to the top of the scroll area, this means that what the user sees in the scroll area changes, because all images are pushed down to make room for the new image.

    But this is not what I want. Instead the scroll area should stick to the same area of the layout, so that the user always sees the same secton of the layout, even when new images are added to the top of scroll area.

    I tried the following code, which does jump a bit into the right direction, but not exactly to the point where it was before the new image has been added:

    scroll_bar = self.scroll_area.verticalScrollBar()
    scroll_bar.setValue(scroll_bar.value() + last_image_label.height())
    

    Any ideas how to achieve this in Qt/PySide2?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Your calculation does not take into account the space between the images due to the layout.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      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