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. QScrollArea with - multiple QWidgets w/ QTreeViews in each
Forum Updated to NodeBB v4.3 + New Features

QScrollArea with - multiple QWidgets w/ QTreeViews in each

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 237 Views 2 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.
  • S Offline
    S Offline
    sbai
    wrote on last edited by sbai
    #1

    I have a scroll area in dockwidget. each scroll area has 2 qwidgets (aka boxes)

    DockWidgets->scrollArea->box1 + box2

    Each box has this hierarchy:
    (box)QWidget->QScrollArea->QLineEdit+ QTreeView

    I have QTreeView bound to a datamodel that works well.
    The following are issues:

    1. both boxes are not covering the entire super parent dockwidget
    2. the qtreeview is always fixed to the init time size
    3. the qtreeview does not change its size when bounded to a model

    when I select box1 its nice to have it fill in all the available vertical space and may be hide box2's content.
    please help.

        MW.scrollArea = QtWidgets.QScrollArea()
        MW.scrollArea.setMinimumWidth(350)
        MW.scrollArea.setWidgetResizable(True)
    
        MW.vboxLeft = QtWidgets.QVBoxLayout(MW.scrollArea)
        MW.vboxLeft.setSpacing(1)
        MW.vboxLeft.setContentsMargins(0, 0, 0, 0)
    
        MW.v1 = CollapsibleWidget("Tree1", MW.scrollArea)
        MW.vboxLeft.addWidget(MW.v1)
    
        MW.v2 = CollapsibleWidget("Tree2", MW.scrollArea)
        MW.vboxLeft.addWidget(MW.v2)
    
        MW.vboxLeft.addStretch()
    
        MW.dockWidget = QtWidgets.QDockWidget("Layout")
        MW.dockWidget.setWidget(MW.scrollArea)
        MW.dockWidget.setFeatures(
            QDockWidget.DockWidgetFloatable |
            QDockWidget.DockWidgetMovable
        )
    
        MW.addDockWidget(Qt.LeftDockWidgetArea, MW.dockWidget)
    
    
    CollapsibleWidget is inspired from a web link 
    class CollapsibleWidget(QtWidgets.QWidget):
        def __init__(self, title="", parent=None):
            super().__init__(parent)
    
            self.toggleButton = QtWidgets.QToolButton(self)
            self.toggleButton.setText(title)
            self.toggleButton.setCheckable(True)
            self.toggleButton.setChecked(True)
            self.toggleButton.setStyleSheet("QToolButton { border: none; }")
            self.toggleButton.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
            self.toggleButton.setArrowType(Qt.RightArrow)
            self.toggleButton.toggled.connect(self.onToggle)
    
            self.contentArea = QtWidgets.QScrollArea(self)
            self.contentArea.setMinimumHeight(0)
            self.contentArea.setMaximumHeight(0)
            self.contentArea.setWidgetResizable(True)
            self.contentArea.setFrameShape(QtWidgets.QFrame.NoFrame)
            self.contentArea.setSizeAdjustPolicy(QAbstractScrollArea.AdjustToContents)
            self.contentArea.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Maximum)
    
            # 0. search box
            self.searchLine = QtWidgets.QLineEdit(self.contentArea)
            self.searchLine.setPlaceholderText("Filter")
    
            self.treeView = QtWidgets.QTreeView(self.contentArea)
            self.treeView.setHeaderHidden(False)
            self.treeView.setRootIsDecorated(True)
            self.treeView.setContentsMargins(0, 0, 0, 0)
            self.treeView.setFont(ProjectSettings.commonFont)
            self.treeView.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Maximum)
    
            self.contentAreaLayout = QtWidgets.QVBoxLayout(self.contentArea)
            self.contentAreaLayout.setSpacing(0)
            self.contentAreaLayout.setContentsMargins(0, 0, 0, 0)
            self.contentAreaLayout.addWidget(self.searchLine)
            self.contentAreaLayout.addWidget(self.treeView)
    
            lay = QtWidgets.QVBoxLayout(self)
            lay.setSpacing(0)
            lay.setContentsMargins(0, 0, 0, 0)
            lay.addWidget(self.toggleButton)
            lay.addWidget(self.contentArea)
    
            self.animationGroup = QParallelAnimationGroup(self)
            contentHeight = self.contentAreaLayout.sizeHint().height()
            collapsedHeight = self.sizeHint().height() - self.contentArea.maximumHeight()
    
            self.setAnimation(
                QPropertyAnimation(self, b"minimumHeight"),
                collapsedHeight, contentHeight
            )
            self.setAnimation(
                QPropertyAnimation(self, b"maximumHeight"),
                collapsedHeight, contentHeight
            )
            self.setAnimation(
                QPropertyAnimation(self.contentArea, b"maximumHeight"),
                0, contentHeight
            )
    
        def setAnimation(self, animation, collapsedHeight, contentHeight):
            animation.setDuration(500)
            animation.setStartValue(collapsedHeight)
            animation.setEndValue(collapsedHeight + contentHeight)
            self.animationGroup.addAnimation(animation)
    
        def onToggle(self):
            arrowType = Qt.RightArrow
            direction = QAbstractAnimation.Backward
    
            if not self.toggleButton.isChecked():
                arrowType = Qt.DownArrow
                direction = QAbstractAnimation.Forward
    
            self.toggleButton.setArrowType(arrowType)
            self.animationGroup.setDirection(direction)
            self.animationGroup.start()
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Do no set the layout on your QScrollArea.

      Set it on a widget that will contain the rest and then set that widget on the QScrollArea.

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

        Thanks for the tip. I will try it out. That applies to both scrollareas - in mainwindow and in collapsiblewidget, right ?

        1 Reply Last reply
        0
        • S Offline
          S Offline
          sbai
          wrote on last edited by
          #4

          Tried, but has the same affect. QTreeView does not take the entire space.

          class CollapsibleWidget(QtWidgets.QWidget):
              def __init__(self, title="", parent=None):
                  super().__init__(parent)
          
                  self.toggleButton = QtWidgets.QToolButton(self)
                  self.toggleButton.setText(title)
                  self.toggleButton.setCheckable(True)
                  self.toggleButton.setChecked(True)
                  self.toggleButton.setStyleSheet("QToolButton { border: none; }")
                  self.toggleButton.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
                  self.toggleButton.setArrowType(Qt.RightArrow)
                  self.toggleButton.toggled.connect(self.onToggle)
          
                  self.contentArea = QtWidgets.QWidget()
          
                  # 0. search box
                  self.searchLine = QtWidgets.QLineEdit(self.contentArea)
                  self.searchLine.setPlaceholderText("Filter (n: Name; a: Address)")
          
                  # 1.tree view
                  self.treeView = QtWidgets.QTreeView(self.contentArea)
                  self.treeView.setHeaderHidden(False)
                  self.treeView.setRootIsDecorated(True)
                  self.treeView.setContentsMargins(0, 0, 0, 0)
                  self.treeView.setFont(ProjectSettings.commonFont)
                  self.treeView.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Maximum)
          
                  self.contentAreaLayout = QtWidgets.QVBoxLayout(self.contentArea)
                  self.contentAreaLayout.setSpacing(0)
                  self.contentAreaLayout.setContentsMargins(0, 0, 0, 0)
                  self.contentAreaLayout.addWidget(self.searchLine)
                  self.contentAreaLayout.addWidget(self.treeView)
          
                  self.scrollArea = QtWidgets.QScrollArea()
                  self.scrollArea.setMinimumHeight(0)
                  self.scrollArea.setMaximumHeight(0)
                  self.scrollArea.setWidgetResizable(True)
                  self.scrollArea.setFrameShape(QtWidgets.QFrame.NoFrame)
                  self.scrollArea.setSizeAdjustPolicy(QAbstractScrollArea.AdjustToContents)
                  self.scrollArea.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Maximum)
                  self.scrollArea.setWidget(self.contentArea)
          
                  lay = QtWidgets.QVBoxLayout(self)
                  lay.setSpacing(0)
                  lay.setContentsMargins(0, 0, 0, 0)
                  lay.addWidget(self.toggleButton)
                  lay.addWidget(self.scrollArea)
          
                  self.animationGroup = QParallelAnimationGroup(self)
                  contentHeight = self.contentAreaLayout.sizeHint().height()
                  collapsedHeight = self.sizeHint().height() - self.scrollArea.maximumHeight()
          
                  self.setAnimation(
                      QPropertyAnimation(self, b"minimumHeight"),
                      collapsedHeight, contentHeight
                  )
                  self.setAnimation(
                      QPropertyAnimation(self, b"maximumHeight"),
                      collapsedHeight, contentHeight
                  )
                  self.setAnimation(
                      QPropertyAnimation(self.scrollArea, b"maximumHeight"),
                      0, contentHeight
                  )
                  print(self.scrollArea.maximumHeight(), self.maximumHeight())
          
              def setAnimation(self, animation, collapsedHeight, contentHeight):
                  animation.setDuration(500)
                  animation.setStartValue(collapsedHeight)
                  animation.setEndValue(collapsedHeight + contentHeight)
                  self.animationGroup.addAnimation(animation)
          
              def onToggle(self):
                  arrowType = Qt.RightArrow
                  direction = QAbstractAnimation.Backward
          
                  if not self.toggleButton.isChecked():
                      arrowType = Qt.DownArrow
                      direction = QAbstractAnimation.Forward
          
                  self.toggleButton.setArrowType(arrowType)
                  self.animationGroup.setDirection(direction)
                  self.animationGroup.start()
          
          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            What do you mean by entire space ?

            Can you show a picture of what you get ?

            What do you expect exactly ?

            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

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved