Skip to main content

A PySide6 widget for collapsible panels, inspired by JavaFX's TitledPane

Project description

CollapsiblePane (PySide6) PyPI Downloads

The CollapsiblePane is a reusable and customizable PySide6 widget that allows users to toggle the visibility of a content area with smooth animations—perfect for organizing UI sections. It mimics JavaFX’s TitledPane behavior and is designed to cleanly encapsulate widgets within collapsible sections.

Inspired by JavaFX's TitledPane.


Features

  • Expand/Collapse content with animation
  • Fully customizable title bar and content styling
  • Add or replace content widgets easily
  • Clean, layout-friendly design
  • Signal support for toggled state

Usage

import sys
from PySide6.QtWidgets import (
    QApplication, QMainWindow, QWidget, QVBoxLayout, QLabel, QLineEdit,
    QComboBox, QCheckBox, QRadioButton, QSlider, QProgressBar,
    QSpinBox, QDateEdit, QTextEdit, QPushButton
)
from PySide6.QtCore import Qt
from collapsiblepane import CollapsiblePane


class Window(QMainWindow):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("CollapsiblePane – Full Customization Demo")
        self.resize(600, 700)

        # --- Collapsible Section ---
        section = CollapsiblePane("User Details", animation_duration=400)

        # --- Header customization ---
        section.set_header_style(
            background_color="#28a745",  # Green header
            text_color="#FFFFFF",         # White text for contrast
            border_color="#1c7c1c",      # Darker green border
            border_width=2,
            font_size=16,
            font_weight="bold",
            hover_color="#32cd32"        # Lighter green hover
        )

        # --- Chevron customization ---
        section.set_chevron_icons("▸", "▾")

        # --- Card content style ---
        section.set_card_style(
            background="#f0fdf4",  # Soft light green background
            border="#28a74533",    # Subtle green border
            radius=10,
            padding=12
        )

        # --- Item count badge ---
        section.set_item_count(23)
        section.set_item_badge_style(
            bg_color="#ffd6e0",     # Light pink
            text_color="#e91e63",   # Dark pink text
            border_color="#ff80ab", # Matching border
            border_radius=12,
            padding_vertical=4,
            padding_horizontal=12,
            font_size=12,
            font_weight="bold",
            shadow=True,
            min_width=40
        )

        # --- Title style ---
        section.set_title_style(color="#ffffff", font_weight="bold", italic=False)

        # --- Content text style ---
        section.set_content_text_style(color="#333333", font_size=14)

        # --- Content Widget ---
        content_widget = QWidget()
        content_layout = QVBoxLayout(content_widget)
        content_layout.setSpacing(8)

        # User input fields
        details_edit = QLineEdit()
        details_edit.setPlaceholderText("Details here...")
        content_layout.addWidget(details_edit)
        name_edit=QLineEdit()
        name_edit.setPlaceholderText("Name here...")
        content_layout.addWidget(name_edit)
        email_edit = QLineEdit()
        email_edit.setPlaceholderText("Email here...")
        content_layout.addWidget(email_edit)

        # Category selection
        content_layout.addWidget(QLabel("Select a category:"))
        combo = QComboBox()
        combo.addItems(["Developer", "Designer", "Security Researcher", "Engineer"])
        content_layout.addWidget(combo)

        # Preferences
        content_layout.addWidget(QCheckBox("Subscribe to newsletter"))
        content_layout.addWidget(QRadioButton("Light Mode"))
        content_layout.addWidget(QRadioButton("Dark Mode"))

        # Volume and progress
        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)

        # Additional inputs
        content_layout.addWidget(QSpinBox())
        content_layout.addWidget(QDateEdit())

        # Bio
        content_layout.addWidget(QLabel("Bio:"))
        text_edit = QTextEdit()
        text_edit.setPlaceholderText("Tell us about yourself...")
        content_layout.addWidget(text_edit)

        # Submit button
        content_layout.addWidget(QPushButton("Submit"))

        # Set the content widget
        section.set_content_widget(content_widget)

        # Force collapsed initially
        section.set_collapsed(collapsed=True)

        # --- Layout Setup ---
        container = QWidget()
        main_layout = QVBoxLayout(container)
        main_layout.addWidget(section)

        toggle_button = QPushButton("Toggle Section")
        toggle_button.clicked.connect(lambda: section.toggle(not section._expanded))
        main_layout.addWidget(toggle_button)

        main_layout.addStretch()
        self.setCentralWidget(container)


if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = Window()
    window.show()
    sys.exit(app.exec())

Screenshot

Collapsed Expanded
Collapsed View Expanded View

API Overview

Constructor

CollapsiblePane(title="", animation_duration=100)

Properties

  • content_widget: QWidget
  • is_expanded: bool

Methods

  • clear_widget()
  • set_content_style(background_color, border_color, ...)
  • set_title_bar_style(background_color, foreground_color)

Signals

  • toggled(bool) — emits when pane expands or collapses

Changelog

  • Added full header customization (set_header_style)
  • Added chevron icon customization (set_chevron_icons)
  • Added card-style content area (set_card_style)
  • Added item count badges with styling API
  • Added title-level text customization
  • Added content text styling
  • Added programmatic expand/collapse methods
  • Added set_content_widget() API
  • Added initial collapsed state support

New Contributor:


Contributions

For contributions please visit Github Repository

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

collapsiblepane-0.10.3.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

collapsiblepane-0.10.3-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file collapsiblepane-0.10.3.tar.gz.

File metadata

  • Download URL: collapsiblepane-0.10.3.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for collapsiblepane-0.10.3.tar.gz
Algorithm Hash digest
SHA256 94dd184ba6af58f10076531185787a2c14b53e4c74a25b58e512830baf2e47c8
MD5 644cd3de8bad454653eacb3c5939fc86
BLAKE2b-256 33fedbc1ab2423881af17558b8622886e6d4cd691b4a6bcdd84f7a232263ade8

See more details on using hashes here.

File details

Details for the file collapsiblepane-0.10.3-py3-none-any.whl.

File metadata

File hashes

Hashes for collapsiblepane-0.10.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d9f40c906d7aac96187f23dee8b7ff4b8b8e4fd06286c1f8e2a4daf33ad3ff4a
MD5 e7e16cf3b5fdd8270037098eb41d5e5a
BLAKE2b-256 97e6de0822dd649db35fb4d9f342aef3db3adc93f35bdc0abed352ccffbfdfdb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page