Home · All Classes · Main Classes · Deprecated |
MLabel provides functionality for displaying text. More...
Inherits MWidgetController.
Public Types | |
enum | PreferredLineCountBehavior { LineCountLimitsPreferredHeight = 0, LineCountSetsPreferredHeight } |
Public Slots | |
void | setText (const QString &text) |
Signals | |
void | linkActivated (const QString &link) |
Public Member Functions | |
MLabel (QGraphicsItem *parent=0, MLabelModel *model=0) | |
MLabel (QString const &text, QGraphicsItem *parent=0) | |
virtual | ~MLabel () |
void | setAlignment (Qt::Alignment alignment) |
Qt::Alignment | alignment () const |
QTextOption::WrapMode | wrapMode () const |
void | setWrapMode (QTextOption::WrapMode wrapMode) |
void | setWordWrap (bool wrap) |
bool | wordWrap () const |
QString | text () const |
QString | renderedText () const |
void | setTextElide (bool elide) |
bool | textElide () const |
void | setPreferredLineCount (int lineCount) |
void | setPreferredLineCount (int lineCount, PreferredLineCountBehavior behavior) |
int | preferredLineCount () const |
void | setFont (const QFont &font) |
QFont | font () const |
void | setColor (const QColor &color) |
QColor | color () const |
void | addHighlighter (MLabelHighlighter *highlighter) |
void | removeHighlighter (MLabelHighlighter *highlighter) |
void | removeAllHighlighters () |
void | setTextFormat (Qt::TextFormat textFormat) |
Qt::TextFormat | textFormat () const |
Properties | |
Qt::Alignment | alignment |
bool | wordWrap |
QTextOption::WrapMode | wrapMode |
bool | textElide |
int | preferredLineCount |
QString | text |
QString | renderedText |
QColor | color |
Qt::TextFormat | textFormat |
MLabel provides functionality for displaying text.
MLabel provides functionality for displaying text. It can display plain text as well as rich text. The positioning of the text can be changed using setAlignment(). The appearance of the text can be tweaked using setTextDirection(), setWordWrap() and setTextElide().
Following list summarizes the functionality of MLabel:
Simple label:
//simple label with text MLabel* label = new MLabel("Simple label"); //set/change the text of label label->setText("Text");
Rich label:
//rich label with bold text. MLabel* label = new MLabel("Rich <b>bold</b> label"); //manual line changes in rich label label->setText("row1<br><i>row2</i><br>row3");
Rich label with custom text color:
QString styledText = "<style>red{color:#FF0000;}</style> <red>Rich</red> label can be <red>styled</red>."; MLabel* label = new MLabel(styledText);
Links in rich label:
//create label with a link QString text = "Rich label can contain <a href=\"http://www.nokia.com\"> links </a>."; MLabel* label = new MLabel(styledText); //connect to signal to receive notification when user clicks a link in label connect(label, SIGNAL(linkActivated(QString)), this, SLOT(linkActivated(QString)));
This enumeration is used by MLabel to indicate how preferredLineCount property affects its preferred height.
MLabel::MLabel | ( | QGraphicsItem * | parent = 0 , |
|
MLabelModel * | model = 0 | |||
) |
Constructs label widget.
parent | optional parent. | |
model | optional model. |
MLabel::MLabel | ( | QString const & | text, | |
QGraphicsItem * | parent = 0 | |||
) | [explicit] |
Constructs a label with a text.
text | Label text. | |
parent | Optional parent. |
MLabel::~MLabel | ( | ) | [virtual] |
Destructs label widget.
void MLabel::addHighlighter | ( | MLabelHighlighter * | highlighter | ) |
Add highlighter object to mlabel.
Qt::Alignment MLabel::alignment | ( | ) | const |
Returns the current alignmentation.
QColor MLabel::color | ( | ) | const |
Returns the color previously set with setColor().
QFont MLabel::font | ( | ) | const |
Return the current font.
The current font is either a font previously set with setFont() or if nothing has been manually set the one that has been defined in css for this particular label.
Overrides QGraphicsWidget::font() const.
void MLabel::linkActivated | ( | const QString & | link | ) | [signal] |
A signal which is emitted when an anchor in the label is clicked.
link contains the clicked link. The signal is only emitted when the link is defined using anchor "<a href=\"http://www.nokia.com"> nokia " html tag.
int MLabel::preferredLineCount | ( | ) | const |
To get the current preferredLineCount() behavior you need to:
model()->preferredLineCountBehavior();
void MLabel::removeAllHighlighters | ( | ) |
Remove all highlighter objects from mlabel.
void MLabel::removeHighlighter | ( | MLabelHighlighter * | highlighter | ) |
Remove highlighter object from mlabel.
QString MLabel::renderedText | ( | ) | const |
Returns the text that is rendered on the display. The rendered text might differ from MLabel::text e.g. because the rendered text got elided or got line breaks.
void MLabel::setAlignment | ( | Qt::Alignment | alignment | ) |
Set an alignmentation for the text.
void MLabel::setColor | ( | const QColor & | color | ) |
void MLabel::setFont | ( | const QFont & | font | ) |
void MLabel::setPreferredLineCount | ( | int | lineCount | ) |
Sets the preferred height returned by sizeHint() to the given number of lines of text.
Equivalent to:
setPreferredLineCount(lineCount, LineCountSetsPreferredHeight);
lineCount | indicates how many lines of text is preferred to be shown. |
Default is -1, disabling this feature.
void MLabel::setPreferredLineCount | ( | int | lineCount, | |
PreferredLineCountBehavior | behavior | |||
) |
Limits or sets the preferred height returned by sizeHint() to the given number of lines of text, with optional behavior.
lineCount | indicates how many lines of text is preferred to be shown. | |
behavior | indicates how preferredLineCount() affects the preferred height of the label. |
Default is -1, disabling this feature.
void MLabel::setText | ( | const QString & | text | ) | [slot] |
Set text for the label.
void MLabel::setTextElide | ( | bool | elide | ) |
Enable/disable automatic text eliding.
If the label doesn't have enough space to show the full text on one line, the will be elided with three dots.
void MLabel::setTextFormat | ( | Qt::TextFormat | textFormat | ) |
Set text format.
This function sets the format in which the label text is displayed. Calling this function with Qt::PlainText or Qt::RichText is used to turn off auto-recognition of text format, calling with Qt::AutoText turns auto-recognition back on.
void MLabel::setWordWrap | ( | bool | wrap | ) |
Enable/disable automatic word wrapping.
If true, wrapping is done according to the mode set with setWrapMode.
void MLabel::setWrapMode | ( | QTextOption::WrapMode | wrapMode | ) |
Set word wrapping mode.
QString MLabel::text | ( | ) | const |
Returns the current text.
bool MLabel::textElide | ( | ) | const |
Returns the elide mode of the label.
Qt::TextFormat MLabel::textFormat | ( | ) | const |
Returns the text format.
This method returns the format in which MLabel displays its text. Note that this function does not give information about the actual format of the label text string, only about the way it is displayed.
bool MLabel::wordWrap | ( | ) | const |
Returns whether the text in label will be wrapped or not.
If the label doesn't have enough space to show the full text on one line, the text will be wrapped to multiple lines.
QTextOption::WrapMode MLabel::wrapMode | ( | ) | const |
Returns wrapping mode for the text in the label.
If the label doesn't have enough space to show the full text on one line, the text will be wrapped to multiple lines if a mode with wrapping behavior is active.
MLabel::alignment [read, write] |
Alignmentation of the label.
See MLabelModel::alignment for details.
MLabel::color [read, write] |
Color of the label text.
See MLabelModel::color for details.
MLabel::preferredLineCount [read, write] |
Limits the preferred height returned sizeHint() to the given number of lines of text.
Default is -1, disabling this feature.
MLabel::renderedText [read] |
Text that is rendered on the display.
See MLabel::renderedText for details.
MLabel::text [read, write] |
Text of the label.
See MLabelModel::text for details.
MLabel::textElide [read, write] |
Text eliding mode of the label.
See MLabelModel::textElide for details.
MLabel::textFormat [read, write] |
Format the label text is displayed in.
This property is used for deciding whether a text string should be interpreted as plain text or rich text. Supported text formats are Qt::PlainText, Qt::RichText and Qt::AutoText. The default format is Qt::AutoText, which causes MLabel to guess the format of the text on a case-by-case basis.
MLabel::wordWrap [read, write] |
Is word wrapping done or not.
QTextOption::WrapMode MLabel::wrapMode [read, write] |
Copyright © 2010 Nokia Corporation | MeeGo Touch |