Skip to main content

A PySide6 custom widget that displays a text label with a configurable indicator.

Project description

IndicatorLabel

A non-interactive custom widget for PySide6 that displays a text label with a configurable indicator.

The indicator can be positioned on the left or right side of the text and changes color based on the checked property.

IndicatorLabel Example

Features

  • Configurable indicator position - indicator on left or right side of the label.
  • ON/OFF state with customizable colors - Bright red (checked) / Dark red (unchecked) by default.
  • Flexible color input - Accepts QColor objects or hex color or natural language strings (e.g., "#FF0000" or "red") See QtColor.fromString
  • StyleSheet support - Override colors via qproperty-* directives.
  • Configurable sizing - Indicator size and spacing from the label text are adjustable.
  • PySide6 Designer support - Use in Qt Designer for visual form editing.

Installation

Requirements

  • Python 3.13+
  • PySide6 6.11.0+

Install from source

# Clone the repository
git clone <repository-url>
cd indicatorlabel

# Install with Poetry
poetry install

# Or install in development mode with pip
pip install -e .

Usage

Quick Start

from PySide6.QtWidgets import QApplication
from indicatorlabel import IndicatorLabel
from PySide6.QtCore import Qt

app = QApplication([])

# Create the widget
label = IndicatorLabel()
label.text = "System Status: Online"
label.checked = True  # bright red
label.setLayoutDirection(Qt.LayoutDirection.LeftToRight)

label.show()
app.exec()

Custom Colors

from PySide6.QtGui import QColor

# Using QColor
label.on_color = QColor(255, 0, 0)      # Bright red when checked
label.off_color = QColor(50, 0, 0)      # Dark red when unchecked

# Using hex strings
label.on_color = "#FF0000"
label.off_color = "#320000"

# Using natural language strings
label.on_color = "green"
label.off_color = "blue"

Sizing and Spacing

# Indicator diameter in pixels (minimum: 4)
label.indicator_size = 16

# Space between indicator and text in pixels
label.spacing = 8

Font Customization

from PySide6.QtGui import QFont

font = QFont("Arial", 14, QFont.Weight.Bold)
label.setFont(font)

StyleSheet Support

# Override colors via stylesheet
label.setStyleSheet("""
    IndicatorLabel {
        qproperty-on_color: #00FF00;
        qproperty-off_color: #003300;
    }
""")

Complete Example

import sys
from PySide6.QtWidgets import QApplication, QVBoxLayout, QWidget
from PySide6.QtGui import QFont, QColor
from indicatorlabel import IndicatorLabel

class MyWindow(QWidget):
    def __init__(self):
        super().__init__()
        layout = QVBoxLayout(self)

        # Active status indicator
        active_label = IndicatorLabel()
        active_label.text = "System: Active"
        active_label.checked = True
        active_label.setLayoutDirection(Qt.LayoutDirection.LeftToRight)
        active_label.setFont(QFont("Segoe UI", 12))
        layout.addWidget(active_label)

        # Inactive status with custom colors
        inactive_label = IndicatorLabel()
        inactive_label.text = "Backup: Standby"
        inactive_label.checked = False
        inactive_label.setLayoutDirection(Qt.LayoutDirection.RightToLeft)
        inactive_label.on_color = QColor(0, 150, 0)      # Green when active
        inactive_label.off_color = QColor(0, 40, 0)      # Dark green when inactive
        layout.addWidget(inactive_label)

        self.show()

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

You can also find a full interactive example in the extra-directory.

PySide6 Designer Integration

IndicatorLabel includes a plugin for PySide6 Designer (pyside6-designer), allowing you to design forms visually.

Setting Up the Designer Plugin

  1. Set the environment variable to point to the plugin directory:

    # Linux/macOS
    export PYSIDE_DESIGNER_PLUGINS=/path/to/indicatorlabel
    
    # Windows
    set PYSIDE_DESIGNER_PLUGINS=C:\path\to\indicatorlabel
    
  2. Launch Designer:

    pyside6-designer
    

How It Works

PySide6 Designer looks for filenames matching register*.py from the directories specified by PYSIDE_DESIGNER_PLUGINS that then load the plugin into the Designer. This project uses registerwidget.py for this.

Loading Designer UI Files

After designing in Designer, generate Python code for a single UI-file with:

pyside6-uic myform.ui -o ui_myform.py

Or use pyside6-project to compile all the project-related QRC- and UI-files. See PySide6-documentation for details.

Use in your application:

from PySide6.QtWidgets import QApplication, QWidget
from ui_myform import Ui_MyForm

class MyWindow(QWidget):
    def __init__(self):
        super().__init__()
        self.ui = Ui_MyForm()
        self.ui.setupUi(self)
        # Access the IndicatorLabel:
        self.ui.indicatorLabel.setText("Updated")

if __name__ == "__main__":
    app = QApplication([])
    window = MyWindow()
    window.show()
    app.exec()

API Reference

Properties

Property Type Description
text str The label text displayed next to the indicator
checked bool True for ON state, False for OFF state
on_color QColor | str indicator color when checked=True
off_color QColor | str indicator color when checked=False
indicator_size int Diameter of the indicator in pixels (minimum: 4)
spacing int Pixels between indicator and text

Methods

Method Description
isChecked() -> bool Get the current checked state
setChecked(bool) Set the checked state
setIndicatorSize(int) Set the indicator diameter
setSpacing(int) Set the indicator-text spacing
setOnColor(QColor | str) Set the ON state color
setOffColor(QColor | str) Set the OFF state color
setFont(QFont) Set the label font
font() -> QFont Get the current font

Signals

Signal Description
stateChanged(bool) Emitted when the checked state changes

Running Examples

The repository includes example scripts to help you get started:

# Built-in demo (run from project root)
poetry run python -m indicatorlabel

# Interactive example with controls
poetry run python extra/example.py

License

This project is licensed under the BSD 3-Clause License - see the LICENSE file for details.

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

indicatorlabel-0.9.1.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

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

indicatorlabel-0.9.1-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file indicatorlabel-0.9.1.tar.gz.

File metadata

  • Download URL: indicatorlabel-0.9.1.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for indicatorlabel-0.9.1.tar.gz
Algorithm Hash digest
SHA256 6ed4f2079f4f3f235b15b85ce849dd2d3f8053fd81ce9029beb9b231c49dc250
MD5 88e7a8e426b06c80c6e12363af152392
BLAKE2b-256 43580b668d535dff1d91d1e1fd61eeeef01004f29eecdbc8d5315ef557f91c8f

See more details on using hashes here.

Provenance

The following attestation bundles were made for indicatorlabel-0.9.1.tar.gz:

Publisher: buildandpublish.yaml on WereCatf/indicatorlabel

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file indicatorlabel-0.9.1-py3-none-any.whl.

File metadata

  • Download URL: indicatorlabel-0.9.1-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for indicatorlabel-0.9.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9ecfc3426a63f60482a000dee4e9e20c0c2a1d6f2026e525d90f103804ea5af6
MD5 d351cb0cb1c76151ef19aa0b00378d47
BLAKE2b-256 3d1b1244604e62568e93df67d701d2bdc65e8b3e0eaa079fa954b427aaafbdad

See more details on using hashes here.

Provenance

The following attestation bundles were made for indicatorlabel-0.9.1-py3-none-any.whl:

Publisher: buildandpublish.yaml on WereCatf/indicatorlabel

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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