|
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.trolltech.qt.QSignalEmitter
com.trolltech.qt.QtJambiObject
com.trolltech.qt.core.QObject
com.trolltech.qt.gui.QWidget
com.trolltech.qt.gui.QFrame
com.trolltech.qt.gui.QLabel
public class QLabel
The QLabel widget provides a text or image display.
QLabel is used for displaying text or an image. No user interaction functionality is provided. The visual appearance of the label can be configured in various ways, and it can be used for specifying a focus mnemonic key for another widget.
A QLabel can contain any of the following content types:
Content | Setting |
---|---|
Plain text | Pass a QString to setText. |
Rich text | Pass a QString that contains rich text to setText. |
A pixmap | Pass a QPixmap to setPixmap. |
A movie | Pass a QMovie to setMovie. |
A number | Pass an int or a double to setNum, which converts the number to plain text. |
Nothing | The same as an empty plain text. This is the default. Set by clear. |
When the content is changed using any of these functions, any previous content is cleared.
The look of a QLabel can be tuned in several ways. All the settings of QFrame are available for specifying a widget frame. The positioning of the content within the QLabel widget area can be tuned with setAlignment and setIndent. Text content can also wrap lines along word bounderies with setWordWrap. For example, this code sets up a sunken panel with a two-line text in the bottom right corner (both lines being flush with the right side of the label):
QLabel *label = new QLabel(this); label->setFrameStyle(QFrame::Panel | QFrame::Sunken); label->setText("first line\nsecond line"); label->setAlignment(Qt::AlignBottom | Qt::AlignRight);
A QLabel is often used as a label for an interactive widget. For this use QLabel provides a useful mechanism for adding an mnemonic (see QKeysequence) that will set the keyboard focus to the other widget (called the QLabel's "buddy"). For example:
QLineEdit* phoneEdit = new QLineEdit(this); QLabel* phoneLabel = new QLabel("&Phone:", this); phoneLabel->setBuddy(phoneEdit);
In this example, keyboard focus is transferred to the label's buddy (the QLineEdit) when the user presses Alt+P. If the buddy was a button (inheriting from QAbstractButton), triggering the mnemonic would emulate a button click.
![]() | A label shown in the Macintosh widget style. |
![]() | A label shown in the Plastique widget style. |
![]() | A label shown in the Windows XP widget style. |
Nested Class Summary |
---|
Nested classes/interfaces inherited from class com.trolltech.qt.gui.QFrame |
---|
QFrame.Shadow, QFrame.Shape, QFrame.StyleMask |
Nested classes/interfaces inherited from class com.trolltech.qt.gui.QWidget |
---|
QWidget.RenderFlag, QWidget.RenderFlags |
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter |
---|
QSignalEmitter.AbstractSignal, QSignalEmitter.Signal0, QSignalEmitter.Signal1<A>, QSignalEmitter.Signal2<A,B>, QSignalEmitter.Signal3<A,B,C>, QSignalEmitter.Signal4<A,B,C,D>, QSignalEmitter.Signal5<A,B,C,D,E>, QSignalEmitter.Signal6<A,B,C,D,E,F>, QSignalEmitter.Signal7<A,B,C,D,E,F,G>, QSignalEmitter.Signal8<A,B,C,D,E,F,G,H>, QSignalEmitter.Signal9<A,B,C,D,E,F,G,H,I> |
Field Summary | |
---|---|
QSignalEmitter.Signal1<java.lang.String> |
linkActivated
This signal is emitted when the user clicks a link. |
QSignalEmitter.Signal1<java.lang.String> |
linkHovered
This signal is emitted when the user hovers over a link. |
Fields inherited from class com.trolltech.qt.gui.QWidget |
---|
customContextMenuRequested |
Constructor Summary | |
---|---|
QLabel()
Equivalent to QLabel(0, 0). |
|
QLabel(QWidget parent)
Equivalent to QLabel(parent, 0). |
|
QLabel(QWidget parent,
Qt.WindowFlags f)
Constructs an empty label. |
|
QLabel(java.lang.String text)
Equivalent to QLabel(text, 0, 0). |
|
QLabel(java.lang.String text,
QWidget parent)
Equivalent to QLabel(text, parent, 0). |
|
QLabel(java.lang.String text,
QWidget parent,
Qt.WindowFlags f)
Constructs a label that displays the text, text. |
Method Summary | |
---|---|
Qt.Alignment |
alignment()
Returns the alignment of the label's contents. |
QWidget |
buddy()
Returns this label's buddy, or 0 if no buddy is currently set. |
protected void |
changeEvent(QEvent arg__1)
This function is reimplemented for internal reasons. |
void |
clear()
Clears any label contents. |
protected void |
contextMenuEvent(QContextMenuEvent ev)
This function is reimplemented for internal reasons. |
boolean |
event(QEvent e)
This function is reimplemented for internal reasons. |
protected void |
focusInEvent(QFocusEvent ev)
This function is reimplemented for internal reasons. |
protected boolean |
focusNextPrevChild(boolean next)
This function is reimplemented for internal reasons. |
protected void |
focusOutEvent(QFocusEvent ev)
This function is reimplemented for internal reasons. |
static QLabel |
fromNativePointer(QNativePointer nativePointer)
This function returns the QLabel instance pointed to by nativePointer |
boolean |
hasScaledContents()
Returns whether the label will scale its contents to fill all available space.. |
int |
heightForWidth(int arg__1)
This function is reimplemented for internal reasons. |
int |
indent()
Returns the label's text indent in pixels. |
protected void |
keyPressEvent(QKeyEvent ev)
This function is reimplemented for internal reasons. |
int |
margin()
Returns the width of the margin. |
QSize |
minimumSizeHint()
This function is reimplemented for internal reasons. |
protected void |
mouseMoveEvent(QMouseEvent ev)
This function is reimplemented for internal reasons. |
protected void |
mousePressEvent(QMouseEvent ev)
This function is reimplemented for internal reasons. |
protected void |
mouseReleaseEvent(QMouseEvent ev)
This function is reimplemented for internal reasons. |
QMovie |
movie()
Returns a pointer to the label's movie, or 0 if no movie has been set. |
boolean |
openExternalLinks()
Specifies whether QLabel should automatically open links using QDesktopServices::openUrl() instead of emitting the anchorClicked() signal. |
protected void |
paintEvent(QPaintEvent arg__1)
This function is reimplemented for internal reasons. |
QPicture |
picture()
Returns the label's picture or null if the label doesn't have a picture. |
QPixmap |
pixmap()
Returns the label's pixmap or null if the label doesn't have a picture. |
void |
setAlignment(Qt.Alignment arg__1)
Sets the alignment of the label's contents to arg__1. |
void |
setAlignment(Qt.AlignmentFlag... arg__1)
Sets the alignment of the label's contents to arg__1. |
void |
setBuddy(QWidget arg__1)
Sets this label's buddy to arg__1. |
void |
setIndent(int arg__1)
Sets the label's text indent in pixels to arg__1. |
void |
setMargin(int arg__1)
Sets the width of the margin to arg__1. |
void |
setMovie(QMovie movie)
Sets the label contents to movie. |
void |
setNum(double arg__1)
Sets the label contents to plain text containing the textual representation of double arg__1. |
void |
setNum(int arg__1)
Sets the label contents to plain text containing the textual representation of integer arg__1. |
void |
setOpenExternalLinks(boolean open)
Specifies whether QLabel should automatically open links using QDesktopServices::openUrl() instead of emitting the anchorClicked() signal. |
void |
setPicture(QPicture arg__1)
Sets the label contents to arg__1. |
void |
setPixmap(QPixmap arg__1)
Sets the label's pixmap to arg__1. |
void |
setScaledContents(boolean arg__1)
Sets whether the label will scale its contents to fill all available space. to arg__1. |
void |
setText(java.lang.String arg__1)
Sets the label's text to arg__1. |
void |
setTextFormat(Qt.TextFormat arg__1)
Sets the label's text format to arg__1. |
void |
setTextInteractionFlags(Qt.TextInteractionFlag... flags)
Specifies how the label should interact with user input if it displays text. |
void |
setTextInteractionFlags(Qt.TextInteractionFlags flags)
Specifies how the label should interact with user input if it displays text. |
void |
setWordWrap(boolean on)
Sets the label's word-wrapping policy to on. |
QSize |
sizeHint()
This function is reimplemented for internal reasons. |
java.lang.String |
text()
Returns the label's text. |
Qt.TextFormat |
textFormat()
Returns the label's text format. |
Qt.TextInteractionFlags |
textInteractionFlags()
Specifies how the label should interact with user input if it displays text. |
boolean |
wordWrap()
Returns the label's word-wrapping policy. |
Methods inherited from class com.trolltech.qt.gui.QFrame |
---|
drawFrame, frameRect, frameShadow, frameShape, frameStyle, frameWidth, lineWidth, midLineWidth, setFrameRect, setFrameShadow, setFrameShape, setFrameStyle, setLineWidth, setMidLineWidth |
Methods inherited from class com.trolltech.qt.core.QObject |
---|
blockSignals, childEvent, children, connectSlotsByName, customEvent, disposeLater, dumpObjectInfo, dumpObjectTree, dynamicPropertyNames, eventFilter, findChild, findChild, findChild, findChildren, findChildren, findChildren, findChildren, installEventFilter, isWidgetType, killTimer, moveToThread, objectName, parent, property, removeEventFilter, setObjectName, setParent, setProperty, signalsBlocked, startTimer, thread, timerEvent |
Methods inherited from class com.trolltech.qt.QtJambiObject |
---|
dispose, disposed, finalize, reassignNativeResources, tr, tr, tr |
Methods inherited from class com.trolltech.qt.QSignalEmitter |
---|
disconnect, disconnect, signalSender |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface com.trolltech.qt.QtJambiInterface |
---|
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership |
Field Detail |
---|
public final QSignalEmitter.Signal1<java.lang.String> linkActivated
This signal is emitted when the user clicks a link. The URL referred to by the anchor is passed in link.
public final QSignalEmitter.Signal1<java.lang.String> linkHovered
This signal is emitted when the user hovers over a link. The URL referred to by the anchor is passed in link.
Constructor Detail |
---|
public QLabel(QWidget parent)
Equivalent to QLabel(parent, 0).
public QLabel()
Equivalent to QLabel(0, 0).
public QLabel(QWidget parent, Qt.WindowFlags f)
Constructs an empty label.
The parent and widget flag f, arguments are passed to the QFrame constructor.
public QLabel(java.lang.String text, QWidget parent)
Equivalent to QLabel(text, parent, 0).
public QLabel(java.lang.String text)
Equivalent to QLabel(text, 0, 0).
public QLabel(java.lang.String text, QWidget parent, Qt.WindowFlags f)
Constructs a label that displays the text, text.
The parent and widget flag f, arguments are passed to the QFrame constructor.
Method Detail |
---|
public final Qt.Alignment alignment()
Returns the alignment of the label's contents.
public final QWidget buddy()
Returns this label's buddy, or 0 if no buddy is currently set.
public final void clear()
Clears any label contents.
public final boolean hasScaledContents()
Returns whether the label will scale its contents to fill all available space..
When enabled and the label shows a pixmap, it will scale the pixmap to fill the available space.
This property's default is false.
public final int indent()
Returns the label's text indent in pixels.
If a label displays text, the indent applies to the left edge if alignment is Qt::AlignLeft, to the right edge if alignment is Qt::AlignRight, to the top edge if alignment is Qt::AlignTop, and to to the bottom edge if alignment is Qt::AlignBottom.
If indent is negative, or if no indent has been set, the label computes the effective indent as follows: If frameWidth is 0, the effective indent becomes 0. If frameWidth is greater than 0, the effective indent becomes half the width of the "x" character of the widget's current font.
public final int margin()
Returns the width of the margin.
The margin is the distance between the innermost pixel of the frame and the outermost pixel of contents.
The default margin is 0.
public final QMovie movie()
Returns a pointer to the label's movie, or 0 if no movie has been set.
public final boolean openExternalLinks()
Specifies whether QLabel should automatically open links using QDesktopServices::openUrl() instead of emitting the anchorClicked() signal.
Note: The textInteractionFlags set on the label need to include either LinksAccessibleByMouse or LinksAccessibleByKeyboard.
The default value is false.
public final void setAlignment(Qt.AlignmentFlag... arg__1)
Sets the alignment of the label's contents to arg__1.
public final void setAlignment(Qt.Alignment arg__1)
Sets the alignment of the label's contents to arg__1.
public final void setBuddy(QWidget arg__1)
Sets this label's buddy to arg__1.
When the user presses the shortcut key indicated by this label, the keyboard focus is transferred to the label's buddy widget.
The buddy mechanism is only available for QLabels that contain text in which one character is prefixed with an ampersand, '&'. This character is set as the shortcut key. See the QShortcut documentation for details (to display an actual ampersand, use '&&').
In a dialog, you might create two data entry widgets and a label for each, and set up the geometry layout so each label is just to the left of its data entry widget (its "buddy"), for example:
QLineEdit *nameEd = new QLineEdit(this);
QLabel *nameLb = new QLabel("&Name:", this);
nameLb->setBuddy(nameEd);
QLineEdit *phoneEd = new QLineEdit(this);
QLabel *phoneLb = new QLabel("&Phone:", this);
phoneLb->setBuddy(phoneEd);
// (layout setup not shown)
With the code above, the focus jumps to the Name field when the user presses Alt+N, and to the Phone field when the user presses Alt+P.
To unset a previously set buddy, call this function with arg__1 set to 0.
public final void setIndent(int arg__1)
Sets the label's text indent in pixels to arg__1.
If a label displays text, the indent applies to the left edge if alignment is Qt::AlignLeft, to the right edge if alignment is Qt::AlignRight, to the top edge if alignment is Qt::AlignTop, and to to the bottom edge if alignment is Qt::AlignBottom.
If indent is negative, or if no indent has been set, the label computes the effective indent as follows: If frameWidth is 0, the effective indent becomes 0. If frameWidth is greater than 0, the effective indent becomes half the width of the "x" character of the widget's current font.
public final void setMargin(int arg__1)
Sets the width of the margin to arg__1.
The margin is the distance between the innermost pixel of the frame and the outermost pixel of contents.
The default margin is 0.
public final void setMovie(QMovie movie)
Sets the label contents to movie. Any previous content is cleared. The label does NOT take ownership of the movie.
The buddy shortcut, if any, is disabled.
public final void setNum(int arg__1)
Sets the label contents to plain text containing the textual representation of integer arg__1. Any previous content is cleared. Does nothing if the integer's string representation is the same as the current contents of the label.
The buddy shortcut, if any, is disabled.
public final void setNum(double arg__1)
Sets the label contents to plain text containing the textual representation of double arg__1. Any previous content is cleared. Does nothing if the double's string representation is the same as the current contents of the label.
The buddy shortcut, if any, is disabled.
public final void setOpenExternalLinks(boolean open)
Specifies whether QLabel should automatically open links using QDesktopServices::openUrl() instead of emitting the anchorClicked() signal.
Note: The textInteractionFlags set on the label need to include either LinksAccessibleByMouse or LinksAccessibleByKeyboard.
The default value is false.
public final void setPicture(QPicture arg__1)
Sets the label contents to arg__1. Any previous content is cleared.
The buddy shortcut, if any, is disabled.
public final void setPixmap(QPixmap arg__1)
Sets the label's pixmap to arg__1.
If no pixmap has been set this will return 0.
Setting the pixmap clears any previous content. The buddy shortcut, if any, is disabled.
public final void setScaledContents(boolean arg__1)
Sets whether the label will scale its contents to fill all available space. to arg__1.
When enabled and the label shows a pixmap, it will scale the pixmap to fill the available space.
This property's default is false.
public final void setText(java.lang.String arg__1)
Sets the label's text to arg__1.
If no text has been set this will return an empty string. Setting the text clears any previous content.
The text will be interpreted either as plain text or as rich text, depending on the text format setting; see setTextFormat. The default setting is Qt::AutoText; i.e. QLabel will try to auto-detect the format of the text set.
If a buddy has been set, the buddy mnemonic key is updated from the new text.
Note that QLabel is well-suited to display small rich text documents, such as small documents that get their document specific settings (font, text color, link color) from the label's palette and font properties. For large documents, use QTextEdit in read-only mode instead. QTextEdit can also provide a scroll bar when necessary.
Note: This function enables mouse tracking if text contains rich text.
public final void setTextFormat(Qt.TextFormat arg__1)
Sets the label's text format to arg__1.
See the Qt::TextFormat enum for an explanation of the possible options.
The default format is Qt::AutoText.
public final void setTextInteractionFlags(Qt.TextInteractionFlag... flags)
Specifies how the label should interact with user input if it displays text.
If the flags contain Qt::LinksAccessibleByKeyboard the focus policy is also automatically set to Qt::StrongFocus. If Qt::TextSelectableByKeyboard is set then the focus policy is set to Qt::ClickFocus.
The default value is Qt::LinksAccessibleByMouse.
public final void setTextInteractionFlags(Qt.TextInteractionFlags flags)
Specifies how the label should interact with user input if it displays text.
If the flags contain Qt::LinksAccessibleByKeyboard the focus policy is also automatically set to Qt::StrongFocus. If Qt::TextSelectableByKeyboard is set then the focus policy is set to Qt::ClickFocus.
The default value is Qt::LinksAccessibleByMouse.
public final void setWordWrap(boolean on)
Sets the label's word-wrapping policy to on.
If this property is true then label text is wrapped where necessary at word-breaks; otherwise it is not wrapped at all.
public final java.lang.String text()
Returns the label's text.
If no text has been set this will return an empty string. Setting the text clears any previous content.
The text will be interpreted either as plain text or as rich text, depending on the text format setting; see setTextFormat. The default setting is Qt::AutoText; i.e. QLabel will try to auto-detect the format of the text set.
If a buddy has been set, the buddy mnemonic key is updated from the new text.
Note that QLabel is well-suited to display small rich text documents, such as small documents that get their document specific settings (font, text color, link color) from the label's palette and font properties. For large documents, use QTextEdit in read-only mode instead. QTextEdit can also provide a scroll bar when necessary.
Note: This function enables mouse tracking if text contains rich text.
public final Qt.TextFormat textFormat()
Returns the label's text format.
See the Qt::TextFormat enum for an explanation of the possible options.
The default format is Qt::AutoText.
public final Qt.TextInteractionFlags textInteractionFlags()
Specifies how the label should interact with user input if it displays text.
If the flags contain Qt::LinksAccessibleByKeyboard the focus policy is also automatically set to Qt::StrongFocus. If Qt::TextSelectableByKeyboard is set then the focus policy is set to Qt::ClickFocus.
The default value is Qt::LinksAccessibleByMouse.
public final boolean wordWrap()
Returns the label's word-wrapping policy.
If this property is true then label text is wrapped where necessary at word-breaks; otherwise it is not wrapped at all.
protected void changeEvent(QEvent arg__1)
This function is reimplemented for internal reasons.
changeEvent
in class QFrame
protected void contextMenuEvent(QContextMenuEvent ev)
This function is reimplemented for internal reasons.
contextMenuEvent
in class QWidget
public boolean event(QEvent e)
This function is reimplemented for internal reasons.
event
in class QFrame
protected void focusInEvent(QFocusEvent ev)
This function is reimplemented for internal reasons.
focusInEvent
in class QWidget
protected boolean focusNextPrevChild(boolean next)
This function is reimplemented for internal reasons.
focusNextPrevChild
in class QWidget
protected void focusOutEvent(QFocusEvent ev)
This function is reimplemented for internal reasons.
focusOutEvent
in class QWidget
public int heightForWidth(int arg__1)
This function is reimplemented for internal reasons.
heightForWidth
in class QWidget
protected void keyPressEvent(QKeyEvent ev)
This function is reimplemented for internal reasons.
keyPressEvent
in class QWidget
public QSize minimumSizeHint()
This function is reimplemented for internal reasons.
minimumSizeHint
in class QWidget
protected void mouseMoveEvent(QMouseEvent ev)
This function is reimplemented for internal reasons.
mouseMoveEvent
in class QWidget
Example
protected void mousePressEvent(QMouseEvent ev)
This function is reimplemented for internal reasons.
mousePressEvent
in class QWidget
Example
protected void mouseReleaseEvent(QMouseEvent ev)
This function is reimplemented for internal reasons.
mouseReleaseEvent
in class QWidget
Example
protected void paintEvent(QPaintEvent arg__1)
This function is reimplemented for internal reasons.
paintEvent
in class QFrame
public QSize sizeHint()
This function is reimplemented for internal reasons.
sizeHint
in class QFrame
public static QLabel fromNativePointer(QNativePointer nativePointer)
nativePointer
- the QNativePointer of which object should be returned.public final QPicture picture()
public final QPixmap pixmap()
|
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |