Text provides a primary means for displaying information in the user
interface. The WText class provides a simple way to add plain
or markup text to the user interface.
The WText widget displays text using an HTML <span>
or <div> element (depending on whether it is inline
or not). It can display either XHTML formatted text or plain text.
The text contents is contained in a WString. This string
class provides at the same time support for localization and
It is a unicode string (internally store as UTF-8) with an
API to interact with plain C++ strings.
It supports localization, when created using WString::tr(). The actual value
corresponding to a key is retrieved from a WLocalizedStrings instance, taking into account the current
locale. The default implementation of this interface class
uses XML files, which are convenient for specifying XHTML
In its most simple form, the WText widget displays plain text
(escaping special characters as needed).
Of course, a WText widget may also display XHTML formatted text.
XHTML text that is not read from a localized strings interface (which is
considered inherently safe), is protected against unwanted side effects
from Cross-Site Scripting (XSS) attacks. The text of an XHTML-formatted
WText is filtered using an XML parser and all malicious tags are
removed (unless this feature is explicitly by-passed by using the
XHTMLUnsafeText text format).
If you want to display a text label associated with a form field then a
WLabel is more suitable as it can be linked to the input
field, relaying focus to it when clicked.
If you want to display an HTML fragment which contains widgets or other
bound contents, then a WTemplate
widget is probably what you are looking for.
The functionality of WText is very basic. As this widget derives
- like many widgets - from WInteractWidget it may respond
to mouse events and also keyboard events if it can be given keyboard
focus. A few mouse events are demonstrated below.
You may add a tooltip or deferred tooltip to WText