Show TOC Welcome to the QLIB 1.0 Online Reference
QLIB 

QLabel


Extends:QControl
Requires:
<script language="JavaScript" src="js/qlib/control.js"></script>
<script language="JavaScript" src="js/qlib/label.js"></script>
Show Demo

Description

Label is a text control that can be dynamically changed. When it changes, it automatically resizes the bounding box to fit new text value. Optionally a label can be created as "clickable". In such case it reacts on user clicks and raises onClick event. Tooltips are supported as an option.

Implementation Notes

Label control is based on DOM2, which is provided by the most new browsers (including but not limited to IE 4 and later, Netscape 6, Netscape 7, Opera 7, Mozilla 1.0 etc). Although archaic Netscape 4.7 browser has no support of DOM2, it's still used on some Linux clones and QLIB includes special implementation of the label just for this case. Opera 6 is an exception (labels are still shown, but set method has no effect).

See Also

UI Controls

Constructor

QLabel(parent, name, valueopt, clickableopt, tooltipopt)
Creates new label. If the label is created as a child control, valid parent object must be specified. If the label object is assigned to global variable, parent should be null. The name should be the same as the name of variable or property that has been assigned by newly created object.
Parameters
parent - Parent control (if any, null otherwise).
name - The object reference name.
value - Optional text for the label (an empty label is created by default).
clickable - Optional. This paremeter must be set to true when the label should raise an event when clicked.
tooltip - Optional tooltip text.

Properties

PropertyAccessDescription
valueRReturns current text on the label. To alter the text use set method.
clickableRIndicates whether the label can raise mouse events.
 
Properties inherited from QControl
nameRName of the control. Serves as a direct reference to this object when evaluated.
idRAlphanumerical unique identifier of the control.
parentRReference to the parent control (if any, null otherwise).
tagR / WCan refer any value or object, tag is always passed to all event handlers as the last parameter.
windowRThis property is a reference to JavaScript window object in which the control exists.
documentRRefers to document object in which the corresponding HTML elements exist. Normally all elements of a DOM2 compatible browser are children of the top document object. If the control creates new document scope (i.e. printing tags like <IFRAME>, <LAYER>), it should assign this document to this property.

Methods

set(valueopt)
Alters the label text. Only plain text is valid. HTML tags and entities are ignored or may lead to undesirable effects. This method is partially supported by some old browsers. See Implementation Notes for details.
Parameters
value - Optional. This parameter should be either text to display on the label or missed. When missed, the label gets cleared up.

Event Handlers

onClick(value, tag)
Is raised by the label when user clicks on it. A label doesn't raise any events when it's not "clickable".
Parameters
value - Text on the label.
tag - Tag is commonly used to parameterize the event handler. Each control can be optionally assigned by a tag.
Returns
The return value is ignored.

Class Constants

ConstantDescription
QLabel.TEXTQUOTAHas effect only for Netscape 4.7. This property controls amount of space that should be reserved for the text area. The default value is 50 chars. If larger space needed, this property must be set by new value before the first constructor call. Though QLIB gets this property documented, it should be considered as a deprecated. We discourage using it since it brings up browser-specific issues into the code.

CSS Class Selectors

CSS ClassDescriptionExample (defined in a CSS file)
DIV.qlabelDefines style properties of a label's DIV element.DIV.qlabel { margin: 10px } /* creates 10px spacing around a label. */