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 can I get the width of a QWidget in a QScrollArea to adapt to the width of the scrollarea?
Forum Updated to NodeBB v4.3 + New Features

How can I get the width of a QWidget in a QScrollArea to adapt to the width of the scrollarea?

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 385 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.
  • O Offline
    O Offline
    olowo726
    wrote on last edited by
    #1

    The user interface in my case is that the user can add any number of child widgets to a QScrollArea by clicking add and remove buttons in a dialog. The child widgets are all of the same class. I would like these child wildgets to get their preferred size vertically and expand horizontally to fill the scrollarea. Hence I've set the resize policy of the child widgets accordingly. For the QScrollarea I've set the properites for scrollbar to never be present horizontally and when needed vertically. The layout of the QScrollArea is a QVBoxLayout.

    The result of these settings is the preferred behavior vertically but horizontally the child widgets gets too large so that they don't fit in the QScollArea. How can I make them expand to fit in the QScrollArea but not more?

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

      Hi,

      There's one thing to take into account: you should not set a layout on QScrollArea but use the setWidget function in order to place your growing widget in there. On that widget you will set the vertical layout where you insert your custom widgets.

      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
      • D Offline
        D Offline
        Dawson1254
        Banned
        wrote on last edited by
        #3
        This post is deleted!
        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