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. QLayouts in a QScrollarea
Forum Updated to NodeBB v4.3 + New Features

QLayouts in a QScrollarea

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 315 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
    CEO.
    wrote on last edited by CEO.
    #1

    Hello great minds, I am having some challenges using scrollarea. It seems to be confusing me. I am building an app which has various classes (windows), I try inserting scrollarea in some of the Windows but being met with challenges. I want the full Window in one of the classes to be scrollable, but it ends up with only a layout being scrollable whereas there are other layouts in the window.

    Now see this code:

    <>class app(QWidget):
    def init(self):
    super().init()
    self.setWindowTitle("QLayouts Management")
    self.resize(270, 110)

    grid = QGridLayout()
    gbox = QGroupBox()
    vbox = QVBoxLayout()
    hbox = QHBoxLayout()
    scrol = QScrollArea()
    secondGrid = QGridLayout()

    secondGbox = QGroupBox()

    self.setLayout(grid)
    grid.addWidget(gbox)
    grid.addWidget(secondGbox)
    scrol.setWidget(gbox)
    grid.addWidget(scrol)

    gbox.setLayout(hbox)
    hbox.addLayout(secondGrid)

    surname = QLabel("Surname:")
    surtx = QLineEdit()
    other = QLabel("Othernames)
    othertx = QLineEdit()

    secondGrid.addWidget(surname,1,0,1,1)
    secondGrid.addWidget(surtx,1,1,1,1)
    secondGrid.addWidget(other,2,1,1,1)
    secondGrid.addWidget(other,2,2,1,1) </>

    
    I would want the whole window to be scrollabe, not only the gBox widget. Please how can I achieve that? I want the scrollarea to be applicable to gbox and secondGbox which make up the gridLayout (main container)
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      If you mean the whole "app" class, then you should create the QScrollArea one level above and put the "app" instance in it.

      If I may, you should name you class something else, app is just going to be confusing with regard to QApplication for example.

      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
      • JoeCFDJ Offline
        JoeCFDJ Offline
        JoeCFD
        wrote on last edited by JoeCFD
        #3

        gbox will be scrolled when needed from your code: scrol.setWidget(gbox).
        If you want the whole widget to be scrollable, create a central widget to hold all of your widgets and add it to scrol.

        1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

          If you mean the whole "app" class, then you should create the QScrollArea one level above and put the "app" instance in it.

          If I may, you should name you class something else, app is just going to be confusing with regard to QApplication for example.

          C Offline
          C Offline
          CEO.
          wrote on last edited by
          #4

          @SGaist thanks for that. It's just an example you know. But all the same, I will keep this in mind.

          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