|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.trolltech.qt.internal.QSignalEmitterInternal
com.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:
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() . |
By default, labels display left-aligned, vertically-centered
text and images, where any tabs in the text to be displayed are automatically expanded
. However, the look of a QLabel
can be adjusted and fine-tuned in several ways.
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 boundaries 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(); label.setFrameStyle(QFrame.Shadow.Sunken.value() | QFrame.Shape.Panel.value() ); label.setText("first line\nsecond line"); label.setAlignment(Qt.AlignmentFlag.AlignBottom, Qt.AlignmentFlag.AlignRight);The properties and functions
QLabel
inherits from QFrame
can also be used to specify the widget frame to be used for any given label. 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(); QLabel phoneLabel = new QLabel("Phone:"); 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. |
QLineEdit
, QTextEdit
, QPixmap
, QMovie
, and GUI Design Handbook: Label.
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, QSignalEmitter.Signal2, QSignalEmitter.Signal3, QSignalEmitter.Signal4, QSignalEmitter.Signal5, QSignalEmitter.Signal6, QSignalEmitter.Signal7, QSignalEmitter.Signal8, QSignalEmitter.Signal9 |
Nested classes/interfaces inherited from class com.trolltech.qt.internal.QSignalEmitterInternal |
---|
com.trolltech.qt.internal.QSignalEmitterInternal.AbstractSignalInternal |
Field Summary | |
---|---|
QSignalEmitter.Signal1 |
linkActivated
This signal takes 1 generic argument(s). |
QSignalEmitter.Signal1 |
linkHovered
This signal takes 1 generic argument(s). |
Fields inherited from class com.trolltech.qt.gui.QWidget |
---|
customContextMenuRequested |
Fields inherited from class com.trolltech.qt.internal.QSignalEmitterInternal |
---|
currentSender |
Constructor Summary | |
---|---|
QLabel()
Constructs an empty label. |
|
QLabel(QWidget parent)
Constructs an empty label. |
|
QLabel(QWidget parent,
Qt.WindowFlags f)
Constructs an empty label. |
|
QLabel(QWidget parent,
Qt.WindowType[] f)
Constructs an empty label. |
|
QLabel(java.lang.String text)
Constructs a label that displays the text, text. |
|
QLabel(java.lang.String text,
QWidget parent)
Constructs a label that displays the text, text. |
|
QLabel(java.lang.String text,
QWidget parent,
Qt.WindowFlags f)
Constructs a label that displays the text, text. |
|
QLabel(java.lang.String text,
QWidget parent,
Qt.WindowType[] f)
Constructs a label that displays the text, text. |
Method Summary | |
---|---|
Qt.Alignment |
alignment()
This property holds the alignment of the label's contents. |
QWidget |
buddy()
Returns this label's buddy, or 0 if no buddy is currently set. |
void |
clear()
Clears any label contents. |
boolean |
hasScaledContents()
This property holds whether the label will scale its contents to fill all available space. |
int |
indent()
This property holds the label's text indent in pixels. |
int |
margin()
This property holds the width of the margin. |
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 linkActivated() signal. |
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)
This property holds the alignment of the label's contents. |
void |
setAlignment(Qt.AlignmentFlag[] arg__1)
This property holds the alignment of the label's contents. |
void |
setBuddy(QWidget arg__1)
Sets this label's buddy to buddy. |
void |
setIndent(int arg__1)
This property holds the label's text indent in pixels. |
void |
setMargin(int arg__1)
This property holds the width of the margin. |
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 num. |
void |
setNum(int arg__1)
Sets the label contents to plain text containing the textual representation of integer num. |
void |
setOpenExternalLinks(boolean open)
Specifies whether QLabel should automatically open links using QDesktopServices::openUrl() instead of emitting the linkActivated() signal. |
void |
setPicture(QPicture arg__1)
Sets the label contents to picture. |
void |
setPixmap(QPixmap arg__1)
This property holds the label's pixmap. |
void |
setScaledContents(boolean arg__1)
This property holds whether the label will scale its contents to fill all available space. |
void |
setText(java.lang.String arg__1)
This property holds the label's text. |
void |
setTextFormat(Qt.TextFormat arg__1)
This property holds the label's text format. |
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)
This property holds the label's word-wrapping policy. |
java.lang.String |
text()
This property holds the label's text. |
Qt.TextFormat |
textFormat()
This property holds the label's text format. |
Qt.TextInteractionFlags |
textInteractionFlags()
Specifies how the label should interact with user input if it displays text. |
boolean |
wordWrap()
This property holds the label's word-wrapping policy. |
Methods inherited from class com.trolltech.qt.gui.QFrame |
---|
frameRect, frameShadow, frameShape, frameStyle, frameWidth, lineWidth, midLineWidth, setFrameRect, setFrameShadow, setFrameShape, setFrameStyle, setLineWidth, setMidLineWidth |
Methods inherited from class com.trolltech.qt.core.QObject |
---|
childEvent, children, connectSlotsByName, customEvent, disposeLater, dumpObjectInfo, dumpObjectTree, dynamicPropertyNames, event, eventFilter, findChild, findChild, findChild, findChildren, findChildren, findChildren, findChildren, indexOfProperty, installEventFilter, isWidgetType, killTimer, moveToThread, objectName, parent, properties, property, removeEventFilter, setObjectName, setParent, setProperty, startTimer, timerEvent, toString, userProperty |
Methods inherited from class com.trolltech.qt.QtJambiObject |
---|
dispose, disposed, equals, finalize, reassignNativeResources, tr, tr, tr |
Methods inherited from class com.trolltech.qt.QSignalEmitter |
---|
blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread |
Methods inherited from class com.trolltech.qt.internal.QSignalEmitterInternal |
---|
__qt_signalInitialization |
Methods inherited from class java.lang.Object |
---|
clone, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface com.trolltech.qt.QtJambiInterface |
---|
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership |
Field Detail |
---|
public final QSignalEmitter.Signal1 linkActivated
This signal takes 1 generic argument(s). We list their type and the name they go by in the description of this signal. <java.lang.String(named: link)>:
This signal is emitted when the user clicks a link. The URL referred to by the anchor is passed in link.
linkHovered()
.
public final QSignalEmitter.Signal1 linkHovered
This signal takes 1 generic argument(s). We list their type and the name they go by in the description of this signal. <java.lang.String(named: link)>:
This signal is emitted when the user hovers over a link. The URL referred to by the anchor is passed in link.
linkActivated()
.
Constructor Detail |
---|
public QLabel(QWidget parent, Qt.WindowType[] f)
The parent and widget flag f, arguments are passed to the QFrame
constructor.
setAlignment()
, setFrameStyle()
, and setIndent()
.
public QLabel(QWidget parent)
The parent and widget flag f, arguments are passed to the QFrame
constructor.
setAlignment()
, setFrameStyle()
, and setIndent()
.
public QLabel()
The parent and widget flag f, arguments are passed to the QFrame
constructor.
setAlignment()
, setFrameStyle()
, and setIndent()
.
public QLabel(QWidget parent, Qt.WindowFlags f)
The parent and widget flag f, arguments are passed to the QFrame
constructor.
setAlignment()
, setFrameStyle()
, and setIndent()
.
public QLabel(java.lang.String text, QWidget parent, Qt.WindowType[] f)
The parent and widget flag f, arguments are passed to the QFrame
constructor.
setText()
, setAlignment()
, setFrameStyle()
, and setIndent()
.
public QLabel(java.lang.String text, QWidget parent)
The parent and widget flag f, arguments are passed to the QFrame
constructor.
setText()
, setAlignment()
, setFrameStyle()
, and setIndent()
.
public QLabel(java.lang.String text)
The parent and widget flag f, arguments are passed to the QFrame
constructor.
setText()
, setAlignment()
, setFrameStyle()
, and setIndent()
.
public QLabel(java.lang.String text, QWidget parent, Qt.WindowFlags f)
The parent and widget flag f, arguments are passed to the QFrame
constructor.
setText()
, setAlignment()
, setFrameStyle()
, and setIndent()
.
Method Detail |
---|
public final Qt.Alignment alignment()
text
.
public final QWidget buddy()
setBuddy()
.
public final void clear()
public final boolean hasScaledContents()
This property's default is false.
public final int indent()
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().
By default, the indent is -1, meaning that an effective indent is calculating in the manner described above.
alignment
, margin
, frameWidth(), and font().
public final int margin()
The default margin is 0.
indent
.
public final QMovie movie()
setMovie()
.
public final boolean openExternalLinks()
QLabel
should automatically open links using QDesktopServices::openUrl()
instead of emitting the linkActivated()
signal. Note: The textInteractionFlags
set on the label need to include either LinksAccessibleByMouse or LinksAccessibleByKeyboard.
The default value is false.
textInteractionFlags()
.
public final void setAlignment(Qt.AlignmentFlag[] arg__1)
text
.
public final void setAlignment(Qt.Alignment arg__1)
text
.
public final void setBuddy(QWidget 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 QKeySequence::mnemonic()
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(); QLabel nameLb = new QLabel("Name:"); nameLb.setBuddy(nameEd); QLineEdit phoneEd = new QLineEdit(); QLabel phoneLb = new QLabel("Phone:"); 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 buddy set to 0.
buddy()
, setText()
, QShortcut
, and setAlignment()
.
public final void setIndent(int arg__1)
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().
By default, the indent is -1, meaning that an effective indent is calculating in the manner described above.
alignment
, margin
, frameWidth(), and font().
public final void setMargin(int arg__1)
The default margin is 0.
indent
.
public final void setMovie(QMovie movie)
The buddy shortcut, if any, is disabled.
movie()
, and setBuddy()
.
public final void setNum(double arg__1)
The buddy shortcut, if any, is disabled.
setText()
, QString::setNum(), and setBuddy()
.
public final void setNum(int arg__1)
The buddy shortcut, if any, is disabled.
setText()
, QString::setNum(), and setBuddy()
.
public final void setOpenExternalLinks(boolean open)
QLabel
should automatically open links using QDesktopServices::openUrl()
instead of emitting the linkActivated()
signal. Note: The textInteractionFlags
set on the label need to include either LinksAccessibleByMouse or LinksAccessibleByKeyboard.
The default value is false.
textInteractionFlags()
.
public final void setPicture(QPicture arg__1)
The buddy shortcut, if any, is disabled.
picture()
, and setBuddy()
.
public final void setPixmap(QPixmap arg__1)
Setting the pixmap clears any previous content. The buddy shortcut, if any, is disabled.
public final void setScaledContents(boolean arg__1)
This property's default is false.
public final void setText(java.lang.String arg__1)
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.
setTextFormat()
, setBuddy()
, and alignment
.
public final void setTextFormat(Qt.TextFormat arg__1)
Qt::TextFormat
enum for an explanation of the possible options. The default format is Qt::AutoText
.
text()
.
public final void setTextInteractionFlags(Qt.TextInteractionFlag[] flags)
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)
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)
By default, word wrap is disabled.
text
.
public final java.lang.String text()
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.
setTextFormat()
, setBuddy()
, and alignment
.
public final Qt.TextFormat textFormat()
Qt::TextFormat
enum for an explanation of the possible options. The default format is Qt::AutoText
.
text()
.
public final Qt.TextInteractionFlags textInteractionFlags()
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()
By default, word wrap is disabled.
text
.
public final QPicture picture()
public final QPixmap pixmap()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |