KMessageWidget Class Reference
from PyKDE5.kwidgetsaddons import *
Inherits: QFrame → QWidget → QObject
Detailed Description
A widget to provide feedback or propose opportunistic interactions.
KMessageWidget can be used to provide inline positive or negative feedback, or to implement opportunistic interactions.
As a feedback widget, KMessageWidget provides a less intrusive alternative to "OK Only" message boxes. If you want to avoid a modal KMessageBox, consider using KMessageWidget instead.
Examples of KMessageWidget look as follows, all of them having an icon set with setIcon(), and the first three show a close button:

"KMessageWidget with different message types"
Negative feedback
The KMessageWidget can be used as a secondary indicator of failure: the first indicator is usually the fact the action the user expected to happen did not happen.
Example: User fills a form, clicks "Submit".
When used to provide negative feedback, KMessageWidget should be placed close to its context. In the case of a form, it should appear on top of the form entries.
KMessageWidget should get inserted in the existing layout. Space should not be reserved for it, otherwise it becomes "dead space", ignored by the user. KMessageWidget should also not appear as an overlay to prevent blocking access to elements the user needs to interact with to fix the failure.
Positive feedback
KMessageWidget can be used for positive feedback but it shouldn't be overused. It is often enough to provide feedback by simply showing the results of an action.
Examples of acceptable uses:
Example of unadapted uses:
Opportunistic interaction
Opportunistic interaction is the situation where the application suggests to the user an action he could be interested in perform, either based on an action the user just triggered or an event which the application noticed.
Example of acceptable uses:
- Since:
- 4.7
Enumerations | |
MessageType | { Positive, Information, Warning, Error } |
Signals | |
hideAnimationFinished () | |
linkActivated (QString contents) | |
linkHovered (QString contents) | |
showAnimationFinished () | |
Methods | |
__init__ (self, QWidget parent=0) | |
__init__ (self, QString text, QWidget parent=0) | |
addAction (self, QAction action) | |
animatedHide (self) | |
animatedShow (self) | |
bool | event (self, QEvent event) |
int | heightForWidth (self, int width) |
QIcon | icon (self) |
bool | isCloseButtonVisible (self) |
bool | isHideAnimationRunning (self) |
bool | isShowAnimationRunning (self) |
KMessageWidget::MessageType | messageType (self) |
QSize | minimumSizeHint (self) |
paintEvent (self, QPaintEvent event) | |
removeAction (self, QAction action) | |
resizeEvent (self, QResizeEvent event) | |
setCloseButtonVisible (self, bool visible) | |
setIcon (self, QIcon icon) | |
setMessageType (self, KMessageWidget::MessageType type) | |
setText (self, QString text) | |
setWordWrap (self, bool wordWrap) | |
QSize | sizeHint (self) |
QString | text (self) |
bool | wordWrap (self) |
Signal Documentation
hideAnimationFinished | ( | ) |
This signal is emitted when the hide animation is finished, started by calling animatedHide(). If animations are disabled, this signal is emitted immediately after the message widget got hidden.
- Note:
- This signal is not emitted if the widget was hidden by calling hide(), so this signal is only useful in conjunction with animatedHide().
- See also:
- animatedHide()
- Since:
- 5.0
- Signal syntax:
QObject.connect(source, SIGNAL("hideAnimationFinished()"), target_slot)
linkActivated | ( | QString | contents | |
) |
This signal is emitted when the user clicks a link in the text label. The URL referred to by the href anchor is passed in contents.
- Parameters:
-
contents text of the href anchor
- See also:
- QLabel.linkActivated()
- Since:
- 4.10
- Signal syntax:
QObject.connect(source, SIGNAL("linkActivated(const QString&)"), target_slot)
linkHovered | ( | QString | contents | |
) |
This signal is emitted when the user hovers over a link in the text label. The URL referred to by the href anchor is passed in contents.
- Parameters:
-
contents text of the href anchor
- See also:
- QLabel.linkHovered()
- Since:
- 4.11
- Signal syntax:
QObject.connect(source, SIGNAL("linkHovered(const QString&)"), target_slot)
showAnimationFinished | ( | ) |
This signal is emitted when the show animation is finished, started by calling animatedShow(). If animations are disabled, this signal is emitted immediately after the message widget got shown.
- Note:
- This signal is not emitted if the widget was shown by calling show(), so this signal is only useful in conjunction with animatedShow().
- See also:
- animatedShow()
- Since:
- 5.0
- Signal syntax:
QObject.connect(source, SIGNAL("showAnimationFinished()"), target_slot)
Method Documentation
__init__ | ( | self, | ||
QWidget | parent=0 | |||
) |
Constructs a KMessageWidget with the specified parent.
__init__ | ( | self, | ||
QString | text, | |||
QWidget | parent=0 | |||
) |
Constructs a KMessageWidget with the specified parent and contents text.
addAction | ( | self, | ||
QAction | action | |||
) |
Add action to the message widget. For each action a button is added to the message widget in the order the actions were added.
- Parameters:
-
action the action to add
- See also:
- removeAction(), QWidget.actions()
animatedHide | ( | self ) |
Hide the widget using an animation.
animatedShow | ( | self ) |
Show the widget using an animation.
bool event | ( | self, | ||
QEvent | event | |||
) |
int heightForWidth | ( | self, | ||
int | width | |||
) |
Returns the required height for width.
- Parameters:
-
width the width in pixels
QIcon icon | ( | self ) |
The icon shown on the left of the text. By default, no icon is shown.
- Since:
- 4.11
bool isCloseButtonVisible | ( | self ) |
Check whether the close button is visible.
- See also:
- setCloseButtonVisible()
bool isHideAnimationRunning | ( | self ) |
Check whether the hide animation started by calling animatedHide() is still running. If animations are disabled, this function always returns false.
- See also:
- animatedHide(), hideAnimationFinished()
- Since:
- 5.0
bool isShowAnimationRunning | ( | self ) |
Check whether the show animation started by calling animatedShow() is still running. If animations are disabled, this function always returns false.
- See also:
- animatedShow(), showAnimationFinished()
- Since:
- 5.0
KMessageWidget::MessageType messageType | ( | self ) |
Get the type of this message. By default, the type is set to KMessageWidget.Information.
- See also:
- KMessageWidget.MessageType, setMessageType()
QSize minimumSizeHint | ( | self ) |
Returns the minimum size of the message widget.
paintEvent | ( | self, | ||
QPaintEvent | event | |||
) |
removeAction | ( | self, | ||
QAction | action | |||
) |
Remove action from the message widget.
- Parameters:
-
action the action to remove
- See also:
- KMessageWidget.MessageType, addAction(), setMessageType()
resizeEvent | ( | self, | ||
QResizeEvent | event | |||
) |
setCloseButtonVisible | ( | self, | ||
bool | visible | |||
) |
Set the visibility of the close button. If visible is true, a close button is shown that calls animatedHide() if clicked.
- See also:
- closeButtonVisible(), animatedHide()
setIcon | ( | self, | ||
QIcon | icon | |||
) |
Define an icon to be shown on the left of the text
- Since:
- 4.11
setMessageType | ( | self, | ||
KMessageWidget::MessageType | type | |||
) |
Set the message type to type. By default, the message type is set to KMessageWidget.Information.
- See also:
- messageType(), KMessageWidget.MessageType
setText | ( | self, | ||
QString | text | |||
) |
Set the text of the message widget to text. If the message widget is already visible, the text changes on the fly.
- Parameters:
-
text the text to display, rich text is allowed
- See also:
- text()
setWordWrap | ( | self, | ||
bool | wordWrap | |||
) |
Set word wrap to wordWrap. If word wrap is enabled, the text() of the message widget is wrapped to fit the available width. If word wrap is disabled, the message widget's minimum size is such that the entire text fits.
- Parameters:
-
wordWrap disable/enable word wrap
- See also:
- wordWrap()
QSize sizeHint | ( | self ) |
Returns the preferred size of the message widget.
QString text | ( | self ) |
Get the text of this message widget.
- See also:
- setText()
bool wordWrap | ( | self ) |
Check whether word wrap is enabled.
If word wrap is enabled, the message widget wraps the displayed text as required to the available width of the widget. This is useful to avoid breaking widget layouts.
- See also:
- setWordWrap()
Enumeration Documentation
MessageType |
Available message types. The background colors are chosen depending on the message type.
- Enumerator:
-
PlainMessage InfoMessage WarningMessage ErrorMessage