API Reference

QNotificationArea

class QNotifications.QNotificationArea.QNotificationArea(targetWidget, *args, **kwargs)[source]

Bases: PyQt5.QtWidgets.QWidget

Notification area to show notifications in. Will be projected on top of another QWidget which should be passed as an argument to this class.

__init__(self, targetWidget, *args, **kwargs)[source]

Constructor

Parameters
targetWidgetQtWidgets.QWidget

The widget to project the notifications on

useGlobalCSSbool (default: False)

Flag which indicates whether global style sheets should be used (which have been set at app-level). If False, the default style sheets stored at self.default_notification_styles will be loaded.

useQueuebool (default: True)

Indicates whether a message queue should be implemented. This will only show maxMessages at the same time and will put all other messages in a queue. Once a message disappears, the next one in the queue will be shown (up to maxMessages at the same time)

maxMessagesint (default: 2)

The number of messages to display at the same time.

Raises
TypeErrorif targetWidget is not an object that inherits QWidget
display(self, message, category, timeout=5000, autohide=False, buttontext=None)[source]

Displays a notification.

If a queue is used, then the notification will only be shown directly if the number of notifications shown is smaller than maxMessages.

Parameters
messagestr

The message to display

category{‘primary’, ‘success’, ‘info’, ‘warning’, ‘danger’}

The type of notification that should be shown. Adheres to bootstrap standards which are primary, success, info, warning and danger

timeoutint, optional

The duration for which the notification should be shown. If None then the notification will be shown indefinitely

buttontextstr, optional

The text to display on the closing button. If not provided a cross will be shown.

Raises
ValueError

if the category is other than one of the expected values.

paintEvent(self, pe)[source]

Redefinition of paintEvent. Makes class QNotificationArea available in style sheets. Internal QT function (do not call directly)

remove(self, notification=None)[source]

Removes a notification.

Parameters
notificationQNotification (default: None)

The notification to remove. This function also serves as a PyQt slot for signals emitted from a QNotification. In this case, the QNotification object is retrieved by using self.sender()

Raises
ValueError

If notification is not None or a QNotification

resizeEvent(self, event)[source]

Internal QT function (do not call directly).

setEntryEffect(self, effect, duration=250)[source]

Sets the effect with which the notifications are to appear.

Parameters
effect{‘fadeIn’, None}

The effect which should be used (for now only ‘fadeIn’ is available) if None is passed for this argument, no effect will be used and the notifcations will just appear directly.

durationint (default: 250 ms)

The duration of the effect in milliseconds

Raises
TypeError

If the object passed for duration is not an int

ValueError

When duration is less than 0, or effect has an invalid value

setExitEffect(self, effect, duration=500)[source]

Sets the effect with which the notifications are to disappear.

Parameters
effect{‘fadeOut’, None}

the effect which should be used (for now only ‘fadeOut’ is available) if None is passed for this argument, no effect will be used and the notifcations will just appear directly.

durationint (default: 1000 ms)

The duration of the effect in milliseconds

Raises
TypeError

If the object passed for duration is not an int

ValueError

When duration is less than 0, or effect has an invalid value

QNotification

class QNotifications.QNotification.QNotification(message, category, timeout=None, autohide=False, buttontext=None, *args, **kwargs)[source]

Bases: PyQt5.QtWidgets.QWidget

Class representing a single notification

__init__(self, message, category, timeout=None, autohide=False, buttontext=None, *args, **kwargs)[source]

Constructor

Parameters
messagestr

The message to show

category{‘primary’, ‘success’, ‘info’, ‘warning’, ‘danger’}

The type of notification. Adheres to bootstrap standard classes which are {primary, success, info, warning, danger}

property category

The currently set category of this notification.

close(self)[source]

Closes the notification.

closeClicked

PyQt signal for click on the notification’s close button.

display(self)[source]

Displays the notification.

enterEvent(self, e)[source]

When the notification is set to auto-hide, it automatically closes when the mouse enters the notifcation.

fadeIn(self, duration)[source]

Fades in the notification.

Parameters
durationint

The desired duration of the animation

Raises
TypeError

if duration is not an integer

fadeOut(self, finishedCallback, duration)[source]

Fades out the notification.

Parameters
finishedCallbackcallable

The function to call after the animation has finished (to for instance clean up the notification)

durationint

The desired duration of the animation

Raises
TypeError

if the wrong datatype is specified for any of the parameters.

property message

The currently set message to display.

onFadeInFinished(self)[source]

Indicates that the fade-in animation is done, so that the notification can be interacted withself.

paintEvent(self, pe)[source]

redefinition of paintEvent, do not call directly. Makes class QNotification available in style sheets. Interal Qt function. Should not be called directly.