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. How to set QScrollArea with stretch

How to set QScrollArea with stretch

Scheduled Pinned Locked Moved Unsolved Qt for Python
4 Posts 2 Posters 844 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.
  • Z Offline
    Z Offline
    Zwenn
    wrote on last edited by
    #1

    Hello, I am trying to create a sidebar for my interface, but I am having some issues. I have a few QPushButtons in a QVBoxLayout. These should then be followed by a QScrollArea, which is then followed by another QVBoxLayout containing some other widgets (see picture). The goal is that the QScrollArea is small so e.g. it only shows lie 4 widgets(lets say QLabels) and if it contains more of these, you have to scroll down to see the other labels. But right now, if I add more labels, the whole ScrollArea widget (and the window size) just gets bigger and the lower part of my window disappears below the taskbar.

    How can i stop the QScrollArea from getting this big?

    I tried setting the stretch but it did not have any influence, I also don't want to set a maximumsize for the scrollarea because i have heard that is bad practice because on bigger screens than mine the widget will not scale according to the screen size increase.Screenshot 2023-01-26 124617.png

    1 Reply Last reply
    0
    • F Offline
      F Offline
      friedemannkleint
      wrote on last edited by
      #2

      Did you set up the scroll area correctly, that is, using QScrollArea::setWidget() to set a viewport widget with a vertical layout containing the widgets to be scrolled?

      1 Reply Last reply
      1
      • Z Offline
        Z Offline
        Zwenn
        wrote on last edited by
        #3

        I believe it is correct, I did the following:
        self.frame=QFrame()
        self.frame.setLayout(QVBoxLayout())
        self.ScrollArea=QScrollArea()
        self.ScrollArea.setWidget(self.frame)
        self.ScrollArea.setWidgetResizable(True)
        #I also tried it without the line above but didn't work either.
        for i in range(10):
        | self.frame.layout().addWidget(QLabel)#or any widget
        self.SideBar.addWidget(self.ScrollArea)
        Is there anything I could do differently?

        1 Reply Last reply
        0
        • F Offline
          F Offline
          friedemannkleint
          wrote on last edited by
          #4

          Other than toying around with the self.ScrollArea.setWidgetResizable(), setting no, this looks correct.

          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