A PySide6 widget for collapsible panels, inspired by JavaFX's TitledPane
Project description
CollapsiblePane (PySide6)
The CollapsiblePane is a reusable Qt widget for PySide6 that allows dynamic expansion and collapsing of a content area. It mimics the behavior of JavaFX’s TitledPane and is designed to group form sections, tool panels, or other widgets under an interactive toggle button.
📆 Class Overview
class CollapsiblePane(QWidget):
A custom QWidget subclass that includes:
- A toggleable title bar (
QToolButton) - A collapsible content area (
QScrollArea) - Animation support using
QParallelAnimationGroupandQPropertyAnimation
✅ Key Features
- Smooth vertical expansion/collapse animations
- Fully customizable title bar and content area styles
- Supports custom styling via colors, borders, and fonts
- Layout-agnostic content insertion via
widget property - Clean and minimal default design, easily adaptable
📸 Demo Preview
| Collapsed | Expanded |
|---|---|
🧪 Usage Example
class Window(QMainWindow):
def __init__(self, parent=None):
super().__init__(parent)
self.setWindowTitle("Flex Zone 🧹")
# Create the collapsible pane
section = CollapsiblePane("🔥 Ultimate Pane of Power", 150, self)
# 🎨 Customize title bar
section.set_title_bar_style(background_color="#0066ff", foreground_color="#FFFFFF")
section.set_content_style(
background_color="#FFFFFF",
border_color="#0066FF",
border_width=2,
border_style="solid"
)
# 💎 Create a widget to hold the layout
content_widget = QWidget()
content_layout = QVBoxLayout(content_widget)
content_layout.addWidget(QLabel("📝 Enter your details:"))
content_layout.addWidget(QLineEdit("Name here..."))
content_layout.addWidget(QLineEdit("Email address..."))
content_layout.addWidget(QLabel("🕽️ Choose a category:"))
combo = QComboBox()
combo.addItems(["Developer", "Designer", "Hacker", "Wizard"])
content_layout.addWidget(combo)
content_layout.addWidget(QCheckBox("Subscribe to newsletter 📬"))
content_layout.addWidget(QRadioButton("Light Mode ☀️"))
content_layout.addWidget(QRadioButton("Dark Mode 🌙"))
content_layout.addWidget(QLabel("🔊 Volume:"))
slider = QSlider(Qt.Horizontal)
slider.setValue(40)
content_layout.addWidget(slider)
progress = QProgressBar()
progress.setValue(70)
content_layout.addWidget(progress)
content_layout.addWidget(QSpinBox())
content_layout.addWidget(QDateEdit())
content_layout.addWidget(QLabel("🧾 Bio:"))
text_edit = QTextEdit()
text_edit.setPlaceholderText("Tell us something cool...")
content_layout.addWidget(text_edit)
content_layout.addWidget(QPushButton("🚀 Launch!"))
# Set the content widget using the property
section.content_widget = content_widget
# 🌟 Main layout
container = QWidget()
main_layout = QVBoxLayout(container)
main_layout.addWidget(section)
main_layout.setAlignment(section, Qt.AlignTop) # <--- THIS does the magic
self.setCentralWidget(container)
if __name__ == "__main__":
app = QApplication(sys.argv)
window = Window()
window.resize(400, 300)
window.show()
sys.exit(app.exec())
🔧 Public Methods
__init__(title: str = "", animation_duration: int = 100, parent: QWidget = None)
Creates a collapsible pane with a given title and animation duration (in ms).
set_title_bar_style(background_color: str, foreground_color: str)
Sets the background and foreground (text) color of the title bar toggle button.
set_content_style(background_color="#ffffff", border_color="#cccccc", border_width=1, border_style="solid")
Sets the content area's background and border styling.
widget property
Sets the widget to the pane.
toggle(collapsed: bool)
Toggles the expansion or collapse of the pane. Called automatically on toggle button interaction.
💡 Design Notes
- The content area is implemented as a
QScrollArea, allowing it to be expandable but scroll-free by default. - Animations are coordinated for both widget height and content height to provide smooth transitions.
- The
QToolButtonis configured with a text label and arrow indicator, acting as the toggle.
🏗️ Dependencies
- PySide6 (
pip install PySide6)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file collapsiblepane-0.1.0.tar.gz.
File metadata
- Download URL: collapsiblepane-0.1.0.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
93d79460a30dc7df1c28aec5a4e5ab3f79d1e8a1f1723cfbf33737c84d273738
|
|
| MD5 |
1ed6cb12b95e1d62c41386d35b31806b
|
|
| BLAKE2b-256 |
1281a6431827d4b0c17fa9d8ce4a30770f2ed14acc03cdfb4cd1f835ceacf0f3
|
File details
Details for the file collapsiblepane-0.1.0-py3-none-any.whl.
File metadata
- Download URL: collapsiblepane-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f204e1ef72bd73deefcfff8f1b27381a803a607adc64817a3718502a8e46e3ab
|
|
| MD5 |
4bc3fa0a0f0ce231ea098521090ea5d6
|
|
| BLAKE2b-256 |
e97b26c22beac257a50e2b329cbe77eb22924caf11085c90602e9f910373fed5
|