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. Dynamically filled QScrollArea does not resize its parent
Forum Updated to NodeBB v4.3 + New Features

Dynamically filled QScrollArea does not resize its parent

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 2 Posters 1.2k 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.
  • J Offline
    J Offline
    Jarek B
    wrote on last edited by
    #1

    Hello all. Since today, I was just a reader and I never feel a need to get an account and ask or answer a question (usually somebody already did that for me, so I just need to look for an answer long enough).

    To the point. I want to create simple dialog with QComboBox that is always visible. Below it there is a container for a dynamically created widgets that will be put there when QComboBox index will change. Because I don't know how many of them will be there I decided that there will be a QScrollArea which will allow to scroll if QDialog will be to tall to be displayed properly (to many widgets to be seen at once).
    On the other hand if the number of items will be to small to scroll up and down it should shrink to match contents.
    I spend couple hours with different approaches and still I am not able to resize QScrollArea.

    The best I got was a proper resize to fit, but without a shrink (widgets are spaced evenly) when I implemented sizeHint for a QScrollArea. Any ideas how to solve that problem? Thank you in advance.

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

      Hi and welcome to devnet,

      Can you show the code you are using ?

      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
      • J Offline
        J Offline
        Jarek B
        wrote on last edited by
        #3

        Thank you for response. I put sample code in the repository https://github.com/bialasjaroslaw/QScrollArea

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

          Just one point I'm not sure to follow. You would like to shrink your dialog if the overall size of the number of combobox shown is small than the current dialog, correct ?

          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
          • J Offline
            J Offline
            Jarek B
            wrote on last edited by
            #5

            Exactly. I probably have not done it, but I would set QDialog minimum/maximum size and if QScrollArea is not able to present them all, then I assume that scrolling will be the only option. On the other hand if contents will be smaller then max size, then QDialog should shrink to fit to contents, but no more than its minimum size (second part is rather optional if it will be too much/too complicated to achieve).

            In presented case QDialog does not have any size limits and even if I change its sizePolicy, it will not cause any difference (at least I am not able to see anything different). It stays the same in case where there is one item or dozen.

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

              What you can do is to use a single shot QTimer with a small value to trigger a slot that will check the sizeHint of scrollAreaWidgetContents and apply the changes you want based on it. Start the timer in addItems.

              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
              • J Offline
                J Offline
                Jarek B
                wrote on last edited by
                #7

                That solved my problem. Thank you a lot.

                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