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. Scrollbar appearing/disappearing infinitely -> override calculation used to display scrollbar in QScrollArea

Scrollbar appearing/disappearing infinitely -> override calculation used to display scrollbar in QScrollArea

Scheduled Pinned Locked Moved Unsolved General and Desktop
qscrollareaqscrollbar
4 Posts 2 Posters 714 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.
  • B Offline
    B Offline
    BryceBeagle
    wrote on 11 Feb 2019, 19:13 last edited by BryceBeagle 2 Nov 2019, 19:25
    #1

    To better explain my issue, let me describe my situation. I have a QScrollArea with a bunch of widgets that expand both vertically and horizontally while maintaining their aspect ratio using heightForWidth. This means that if their width is increased, their height will too. If their width is decreased, so will their height.

    If my QScrollArea is barely smaller than the height of all my widgets once they have expanded vertically, the vertical scrollbar will appear. This reduces the width available to my widgets and their height will in turn decrease. Now, all the widgets fit inside the viewport again and the scrollbar is removed. More space is available to the widgets and they expand out of the viewport. The scrollbar appears again.... This process keeps repeating and the scrollbar appears and disappears infinitely, constantly resizing my widgets.

    I'm looking for a proper solution to this problem other than having the scrollbar always visible.

    I found that there is a function in QAbstractScrollArea called maximumViewportSize but it's unfortunately not a virtual function. For a test, I manually overrode resizeEvent which calls updateScrollbars (also not virtual), which in turn calls maximumViewPortSize. I made my own maximumViewportSize that subtracted the width of a scrollbar to the viewport's width calculation and it worked perfectly. Unfortunately, this required reimplementing a lot of functions and is not very maintainable.

    Is there a better solution here?

    I can provide a MVCE if necessary.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 11 Feb 2019, 21:10 last edited by
      #2

      Hi and welcome to devnet,

      Might be a silly idea but can't you force the resizing to happen such as their total height passes the threshold that triggers your problem ?

      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
      • B Offline
        B Offline
        BryceBeagle
        wrote on 11 Feb 2019, 23:29 last edited by
        #3

        Sorry, I'm not sure if I understand your response... What resizing are you referring to? The resizing of the viewport or of the widgets?

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 12 Feb 2019, 22:39 last edited by
          #4

          I was thinking about the widgets.

          By the way, how are you adding them to the QScrollArea ?

          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

          1/4

          11 Feb 2019, 19:13

          • Login

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