Skip to main content

QCustomAlert

QCustomAlert screenshot

QCustomAlert is an inline callout / banner — a static message block with a leading glyph, an optional title, the message text, and an optional close button. Unlike a transient toast, it stays on the page. Four semantic variants colour it from the design tokens.


Overview

  • Four variants via the variant property — info / success / warning / destructive — each with a matching glyph and a coloured left bar/icon/title.
  • Optional title + wrapping message text.
  • Optional dismiss button that hides the alert and emits closed.
  • Tokenized; follows the active theme.

Constructor

QCustomAlert(parent=None, title="", text="", variant="info", dismissible=False)
  • title — bold heading (hidden when empty).
  • text — the message body (hidden when empty).
  • variantinfo / success / warning / destructive (unknown → info).
  • dismissible — show a close button.

Properties

PropertyTypeDescription
variantstrinfo / success / warning / destructive.
titlestrHeading text.
textstrMessage body.
dismissibleboolWhether the close button is shown.

Methods

MethodDescription
setTitle(title)Set the heading (hidden when empty).
setText(text)Set the message (hidden when empty).
setDismissible(on)Show/hide the close button.
isDismissible()Whether it's dismissible.
closeButton()The close QPushButton.

Signals

SignalDescription
closed()Emitted when the user dismisses the alert (it also hides).

Usage example

from qtpy.QtWidgets import QApplication, QWidget, QVBoxLayout
from Custom_Widgets.QCustomAlert import QCustomAlert
from Custom_Widgets.JSonStyles.tokens import DesignTokens, applyDesignTokens

app = QApplication([])
applyDesignTokens(app, tokens=DesignTokens(theme="light"))

w = QWidget()
col = QVBoxLayout(w)
col.addWidget(QCustomAlert(title="Heads up", text="Your trial ends in 3 days.",
variant="info"))
col.addWidget(QCustomAlert(title="Saved", text="Settings updated.",
variant="success"))
err = QCustomAlert(title="Error", text="Payment failed.", variant="destructive",
dismissible=True)
err.closed.connect(lambda: print("dismissed"))
col.addWidget(err)
w.show()
app.exec()

Theming

Styled from the design tokens (alert_qss) via applyDesignTokens; each variant maps to a semantic role (info / success / warning / destructive). See Theming.

API reference

Generated from the widget's live metaobject — do not edit by hand.

Properties

PropertyTypeDefault
variantenum: info/success/warning/destructive``info
titlestring
textstring
dismissibleboolFalse

Signals

Signal
closed()

Methods

MethodDescription
closeButton()Close the button.
closed(...)Closed.
dismissible(*args, **kwargs)Dismissible.
isDismissible()Return whether the widget is dismissible.
setDismissible(dismissible)Set the dismissible.
setText(text)Set the text.
setTitle(title)Set the title.
text(*args, **kwargs)Text.
title(*args, **kwargs)Title.
variant(*args, **kwargs)Variant.