Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: MichaelVoelkel/qt-collapsible-section
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: eyalk11/qt-collapsible-section-pyside6
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 7 commits
  • 4 files changed
  • 2 contributors

Commits on Mar 17, 2023

  1. Update README.md

    eyalk11 authored Mar 17, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    53d1223 View commit details
  2. Update README.md

    eyalk11 authored Mar 17, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    4a1a32d View commit details
  3. Copy the full SHA
    30e0c73 View commit details
  4. Added Setup

    eyalk11 committed Mar 17, 2023
    Copy the full SHA
    9dead87 View commit details
  5. Fixed Setup

    eyalk11 committed Mar 17, 2023
    Copy the full SHA
    f27c70b View commit details

Commits on Aug 30, 2023

  1. Update version

    eyalk11 authored Aug 30, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    3f6d8ed View commit details
  2. Update setup.py

    eyalk11 authored Aug 30, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    5d33e72 View commit details
Showing with 51 additions and 31 deletions.
  1. +5 −0 README.md
  2. +31 −31 { → qt_collapsible_section}/Section.py
  3. +1 −0 qt_collapsible_section/__init__.py
  4. +14 −0 setup.py
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -6,6 +6,10 @@ Special thanks to "x squared" who has posted the original code for this idea at

A python version is available, using PyQt5, as Section.py.

## Changes in this fork

* Adapted to PySide6

## Sample Code

Section* section = new Section("Section", 300, parentWidget);
@@ -18,3 +22,4 @@ A python version is available, using PyQt5, as Section.py.
## Sample Animation

![section opening and closing](example.gif)

62 changes: 31 additions & 31 deletions Section.py → qt_collapsible_section/Section.py
Original file line number Diff line number Diff line change
@@ -1,79 +1,78 @@
'''
Elypson/qt-collapsible-section
(c) 2016 Michael A. Voelkel - michael.alexander.voelkel@gmail.com
This file is part of Elypson/qt-collapsible section.
Elypson/qt-collapsible-section is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, version 3 of the License, or
(at your option) any later version.
Elypson/qt-collapsible-section is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU General Public License
along with Elypson/qt-collapsible-section. If not, see <http:#www.gnu.org/licenses/>.
'''

import PyQt5.QtCore as cr
import PyQt5.QtWidgets as wd
import PySide6.QtCore as cr
import PySide6.QtWidgets as wd
# import PyQt5.QtGui as gui
import sys

class Section(wd.QWidget):
def __init__(self, title="", animationDuration=100, parent=None):
def __init__(self, parent=None,*, animationDuration=100):
super().__init__(parent)
self.animationDuration = animationDuration
self.toggleButton = wd.QToolButton(self)
self.headerLine = wd.QFrame(self)
self.toggleAnimation = cr.QParallelAnimationGroup(self)
self.contentArea = wd.QScrollArea(self)
self.mainLayout = wd.QGridLayout(self)
self.toggleButton.setStyleSheet("QToolButton {border: none;}")
self.toggleButton.setToolButtonStyle(cr.Qt.ToolButtonTextBesideIcon)
self.toggleButton.setArrowType(cr.Qt.RightArrow)
self.toggleButton.setText(title)

self.toggleButton.setToolButtonStyle(cr.Qt.ToolButtonStyle.ToolButtonTextBesideIcon)
#self.toggleButton.setStyleSheet("QToolButton {border: none;}")
self.toggleButton.setArrowType(cr.Qt.ArrowType.RightArrow)
#self.toggleButton.setText(title)
self.toggleButton.setCheckable(True)
self.toggleButton.setChecked(False)

self.headerLine.setFrameShape(wd.QFrame.HLine)
self.headerLine.setFrameShadow(wd.QFrame.Sunken)
self.headerLine.setSizePolicy(wd.QSizePolicy.Expanding, wd.QSizePolicy.Maximum)

# self.contentArea.setLayout(wd.QHBoxLayout())
self.contentArea.setSizePolicy(wd.QSizePolicy.Expanding, wd.QSizePolicy.Fixed)

# start out collapsed
self.contentArea.setMaximumHeight(0)
self.contentArea.setMinimumHeight(0)

# let the entire widget grow and shrink with its content
self.toggleAnimation.addAnimation(cr.QPropertyAnimation(self, b"minimumHeight"))
self.toggleAnimation.addAnimation(cr.QPropertyAnimation(self, b"maximumHeight"))
self.toggleAnimation.addAnimation(cr.QPropertyAnimation(self.contentArea, b"maximumHeight"))

self.mainLayout.setVerticalSpacing(0)
self.mainLayout.setContentsMargins(0, 0, 0, 0)

row = 0
self.mainLayout.addWidget(self.toggleButton, row, 0, 1, 1, cr.Qt.AlignLeft)
self.mainLayout.addWidget(self.toggleButton, row, 0, 1, 1)
self.mainLayout.addWidget(self.headerLine, row, 2, 1, 1)
self.mainLayout.addWidget(self.contentArea, row+1, 0, 1, 3)
self.mainLayout.addWidget(self.contentArea, row + 1, 0, 1, 3)
self.setLayout(self.mainLayout)

self.toggleButton.toggled.connect(self.toggle)


def setTitle(self,title):
self.toggleButton.setText(title)

def setContentLayout(self, contentLayout):
layout = self.contentArea.layout()
del layout
self.contentArea.setLayout(contentLayout)
collapsedHeight = self.sizeHint().height() - self.contentArea.maximumHeight()
contentHeight = contentLayout.sizeHint().height()
for i in range(0, self.toggleAnimation.animationCount()-1):
for i in range(0, self.toggleAnimation.animationCount() - 1):
SectionAnimation = self.toggleAnimation.animationAt(i)
SectionAnimation.setDuration(self.animationDuration)
SectionAnimation.setStartValue(collapsedHeight)
@@ -85,33 +84,34 @@ def setContentLayout(self, contentLayout):

def toggle(self, collapsed):
if collapsed:
self.toggleButton.setArrowType(cr.Qt.DownArrow)
self.toggleButton.setArrowType(cr.Qt.ArrowType.DownArrow)
self.toggleAnimation.setDirection(cr.QAbstractAnimation.Forward)
else:
self.toggleButton.setArrowType(cr.Qt.RightArrow)
self.toggleButton.setArrowType(cr.Qt.ArrowType.RightArrow)
self.toggleAnimation.setDirection(cr.QAbstractAnimation.Backward)
self.toggleAnimation.start()


if __name__ == '__main__':
class Window(wd.QMainWindow):
def __init__(self, parent=None):
super().__init__(parent)
section = Section("Section", 100, self)

anyLayout = wd.QVBoxLayout()
anyLayout.addWidget(wd.QLabel("Some Text in Section", section))
anyLayout.addWidget(wd.QPushButton("Button in Section", section))

section.setContentLayout(anyLayout)

self.place_holder = wd.QWidget() # placeholder widget, only used to get acces to wd.QMainWindow functionalities
mainLayout = wd.QHBoxLayout(self.place_holder)
mainLayout.addWidget(section)
mainLayout.addStretch(1)
self.setCentralWidget(self.place_holder)


app = wd.QApplication(sys.argv)
window = Window()
window.show()
sys.exit(app.exec_())

sys.exit(app.exec_())
1 change: 1 addition & 0 deletions qt_collapsible_section/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .Section import Section
14 changes: 14 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from setuptools import setup

setup(
name='qt-collapsible-section-pyside6',
version='0.1.0',
packages=['qt_collapsible_section'],
url='https://github.com/eyalk11/qt-collapsible-section',
license='LGPL',
author='Michael A. Voelkel ',
author_email='michael.alexander.voelkel@gmail.com',
description='This is a simple collapsable section for PySide6',
install_requires=
['PySide6']
)