Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. QScrollArea stops limiting parent QDialog size
Forum Updated to NodeBB v4.3 + New Features

QScrollArea stops limiting parent QDialog size

Scheduled Pinned Locked Moved Unsolved Qt for Python
3 Posts 2 Posters 306 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.
  • C Offline
    C Offline
    Cerno_b
    wrote on last edited by
    #1

    I am using Qt5 with PySide2

    I am experiencing some behavior that is different from what I would expect. Would anyone be able to clarify if I am misunderstanding something?

    As soon as I add a QScrollArea to a QDialog, I lose the ability to constrain the dialog's maximum size by the scrollbar contents' minimum size. This is expected behavior from a QScrollArea I think, but it persists when I switch the scrollbars off, which is not what I would expect.

    My setup is fairly simple:

    • In Designer, create a new QDialog
    • Add a QListWidget
    • Set the dialog's layout to vertical
    • Set the list widget's minimum width to 600

    Run the code. I can now resize the dialog, but I can't make it smaller than the list widget's size allows. This is what I expected.

    Now add some changes:

    • Place a QScrollArea on the QDialog
    • Move the list widget to the scroll area
    • Set the scroll area's layout to vertical

    Run the code again. The dialog can now be resized to be smaller than the list widget's size allows and a scrollbar appears when I do. This is also what I expected.

    One final change:

    • Set the scroll area's horizontal scroll bar policy to ScrollBarAlwaysOff

    Run the code.

    • Behavior: The same as with the scrollbar enabled (I can make the dialog smaller than the list widget allows). The only difference is that the scrollbar is not shown.
    • Expected: The switched-off scroll bar enforces the dialog's maximum size to obey the list widget's minimum width as it would in the first example.

    So what I am looking for is a QScrollArea that behaves exactly like a QScrollArea in vertical direction, but that behaves exactly as if it did not exist in horizontal direction.

    I am trying to avoid doing any manual calculations on the window size if possible.

    Is this a limitation in Qt or did I miss a setting that would allow getting this behavior?

    1 Reply Last reply
    0
    • SGaistS SGaist moved this topic from General and Desktop on
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      If you want to achieve that you have to set the constraint yourself on the QScrollArea width when you hide the scrollbar.

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

      C 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        If you want to achieve that you have to set the constraint yourself on the QScrollArea width when you hide the scrollbar.

        C Offline
        C Offline
        Cerno_b
        wrote on last edited by
        #3

        @SGaist Thanks for your input.

        Can you clarify what you mean with "set the constraint"? Do you mean I need to limit the QScrollArea's width at some magic number? Because that's what I wanted to avoid.

        I was looking for a solution that allows auto-formatting, but not the way a QScrollArea does but rather the way a QWidget does it, so I get the QScrollArea behaviour in one direction and the QWidget behaviour in the other direction.

        And maybe clarification: Is this behaviour by design? I would kind of expect that a disabled scroll bar would not replicate the resizing behaviour as if a scroll bar was present, or is there a use case I am missing?

        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