📄 qlabel.3qt
字号:
.TH QLabel 3qt "6 July 1999" "Troll Tech AS" \" -*- nroff -*-.\" Copyright 1992-1999 Troll Tech AS. All rights reserved. See the.\" license file included in the distribution for a complete license.\" statement..\".ad l.nh.SH NAMEQLabel \- Displays a static text or pixmap.SH SYNOPSIS.br.PP\fC#include <qlabel.h>\fR.PPInherits QFrame..PP.SS "Public Members".in +1c.ti -1c.BI "\fBQLabel\fR ( QWidget * " "parent" ", const char * " "name" "=0, WFlags " "f" "=0 )".br.ti -1c.BI "\fBQLabel\fR ( const QString & " "text" ", QWidget * " "parent" ", const char * " "name" "=0, WFlags " "f" "=0 )".br.ti -1c.BI "\fBQLabel\fR ( QWidget * " "buddy" ", const QString &, QWidget * " "parent" ", const char * " "name" "=0, WFlags " "f" "=0 )".br.ti -1c.BI "\fB~QLabel\fR ()".br.ti -1c.BI "QString \fBtext\fR () const".br.ti -1c.BI "QPixmap* \fBpixmap\fR () const".br.ti -1c.BI "QMovie* \fBmovie\fR () const".br.ti -1c.BI "Qt::TextFormat \fBtextFormat\fR () const".br.ti -1c.BI "void \fBsetTextFormat\fR ( Qt::TextFormat )".br.ti -1c.BI "int \fBalignment\fR () const".br.ti -1c.BI "virtual void \fBsetAlignment\fR ( int )".br.ti -1c.BI "int \fBindent\fR () const".br.ti -1c.BI "void \fBsetIndent\fR ( int )".br.ti -1c.BI "bool \fBautoResize\fR () const".br.ti -1c.BI "virtual void \fBsetAutoResize\fR ( bool )".br.ti -1c.BI "virtual QSize \fBsizeHint\fR () const".br.ti -1c.BI "virtual QSizePolicy \fBsizePolicy\fR () const".br.ti -1c.BI "virtual void \fBsetBuddy\fR ( QWidget * )".br.ti -1c.BI "QWidget* \fBbuddy\fR () const".br.ti -1c.BI "virtual void \fBsetAutoMask\fR ( bool )".br.ti -1c.BI "virtual int \fBheightForWidth\fR ( int ) const".br.in -1c.SS "Public Slots".in +1c.ti -1c.BI "virtual void \fBsetText\fR ( const QString & )".br.ti -1c.BI "virtual void \fBsetPixmap\fR ( const QPixmap & )".br.ti -1c.BI "virtual void \fBsetMovie\fR ( const QMovie & )".br.ti -1c.BI "virtual void \fBsetNum\fR ( int )".br.ti -1c.BI "virtual void \fBsetNum\fR ( double )".br.ti -1c.BI "void \fBclear\fR ()".br.in -1c.SS "Protected Members".in +1c.ti -1c.BI "virtual void \fBdrawContents\fR ( QPainter * )".br.ti -1c.BI "virtual void \fBdrawContentsMask\fR ( QPainter * )".br.in -1c.SH DESCRIPTIONThe QLabel widget displays a static text or pixmap..PPA label is a static text or pixmap field..PPIt can have a frame (since QLabel inherits QFrame) and a "buddy" and an accelerator for moving keyboard focus to the buddy..PPThe contents of a label can be specified as a normal text, as a numeric value (which is internally converted to a text) or, as a pixmap. If the label is normal text and one of the letters is prefixed with '&', you can also specify a \fIbuddy\fR for the label:.PP.nf.br QLineEdit * phone = new QLineEdit( this, "phone number" );.br QLabel * phoneLabel = new QLabel( phone, "&Phone", this );.fi.PPIn this example, keyboard focus is transferred to the label's buddy (the QLineEdit) when the user presses \fIAlt-P.\fR This is handy for many dialogs. You can also use the setBuddy() function to accomplish the same means..PPA label can be aligned in many different ways. The alignment setting specifies where to position the contents relative to the frame rectangle. See setAlignment() for a description of the alignment flags..PPEnabling auto-resizing make the label resize itself whenever the contents change. The top left corner does not move..PPThis code sets up a sunken panel with a two-line text in the bottom right corner:.PP.nf.br QLabel *label = new QLabel;.br label->setFrameStyle( QFrame::Panel | QFrame::Sunken );.br label->setText( "first line\\nsecond line" );.br label->setAlignment( AlignBottom | AlignRight );.fi.PPBoth lines are flush with the right side of the label..PP<img src=qlabel-m.png> <img src=qlabel-w.png>.PPA label may also be used to provide a slightly larger amount of information, for example a few lines help text in a dialog. For this reason, QLabel also supports rich text rendering. The available styles are defined in the default stylesheet QStyleSheet::defaultSheet(). Usually the label autodetects from the set text whether rich text rendering is required. The format, however, can also be specified directly with setTextFormat(). Note that buddies will not work yet with rich text labels since there's not way to specify the accelerator (yet)..PPSee also: QLineEdit, QMovie, QTextView and GUI Design Handbook: Label.PPExamples:.(ltabdialog/tabdialog.cpp cursor/cursor.cpp layout/layout.cpp popup/popup.cpp menu/menu.cpp progress/progress.cpp qmag/qmag.cpp movies/main.cpp customlayout/main.cpp.)l.SH MEMBER FUNCTION DOCUMENTATION.SH "QLabel::QLabel ( QWidget * buddy, const QString & text, QWidget * parent, const char * name=0, WFlags f=0 )"Constructs a label with an accelerator key..PPThe \fIparent, name\fR and \fIf\fR arguments are passed to the QFrame constructor. Note that the \fIparent\fR argument does \fInot\fR default to 0..PPIn a dialog, you might create two data entry widgets and a label for each, and set up the geometry so each label is just to the left of its data entry widget (its "buddy"), somewhat like this:.PP.nf.br QLineEdit *name = new QLineEdit( this );.br QLabel *name_l = new QLabel( name, "&Name:", this );.br QLineEdit *phone = new QLineEdit( this );.br QLabel *phone_l = new QLabel( phone, "&Phone:", this );.br // geometry management setup not shown.fi.PPWith 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..PPSee also: setText() and setBuddy()..SH "QLabel::QLabel ( QWidget * parent, const char * name=0, WFlags f=0 )"Constructs an empty label which is left-aligned, vertically centered, has an automatic indent and with manual resizing..PPThe \fIparent, name\fR and \fIf\fR arguments are passed to the QFrame constructor..PPSee also: setAlignment(), setFrameStyle(), setIndent() and setAutoResize()..SH "QLabel::QLabel ( const QString & text, QWidget * parent, const char * name=0, WFlags f=0 )"Constructs a label with a text. The label is left-aligned, vertically centered, has an automatic indent and with manual resizing..PPThe \fIparent, name\fR and \fIf\fR arguments are passed to the QFrame constructor..PPSee also: setAlignment(), setFrameStyle(), setIndent() and setAutoResize()..SH "QLabel::~QLabel ()"Destroys the label..SH "int QLabel::alignment () const"Returns the alignment setting..PPThe default alignment is \fCAlignLeft | AlignVCenter | ExpandTabs\fR if the label doesn't have a buddy and \fCAlignLeft | AlignVCenter | ExpandTabs | ShowPrefix \fR if the label has a buddy..PPSee also: setAlignment()..SH "bool QLabel::autoResize () const"Returns TRUE if auto-resizing is enabled, or FALSE if auto-resizing is disabled..PPAuto-resizing is disabled by default..PPSee also: setAutoResize()..SH "QWidget * QLabel::buddy () const"Returns the buddy of this label..SH "void QLabel::clear () \fC[slot]\fR"Clears the label. Equivalent with setText( "" )..SH "void QLabel::drawContents ( QPainter * p ) \fC[virtual protected]\fR"Draws the label contents using the painter \fIp.\fR.PPReimplemented from QFrame..SH "void QLabel::drawContentsMask ( QPainter * p ) \fC[virtual protected]\fR"Draws the label contents mask using the painter \fIp.\fR Used only in transparent mode..PPSee also: QWidget::setAutoMask();..PPReimplemented from QFrame..SH "int QLabel::heightForWidth ( int w ) const \fC[virtual]\fR"Reimplemented for rich text labels and WordBreak..PPReimplemented from QWidget..SH "int QLabel::indent () const"Returns the indent of the label..PPSee also: setIndent()..SH "QMovie* QLabel::movie () const"Returns the QMovie currently displaying in the label, or 0 if none has been set..PPSee also: setMovie() and unsetMovie()..SH "QPixmap * QLabel::pixmap () const"Returns the label pixmap..PPSee also: setPixmap()..SH "void QLabel::setAlignment ( int alignment ) \fC[virtual]\fR"Sets the alignment of the label contents and redraws itself..PPThe \fIalignment\fR is the bitwise OR of the following flags:.TP\fCAlignLeft\fR aligns to the left border..TP\fCAlignRight\fR aligns to the right border..TP\fCAlignHCenter\fR aligns horizontally centered..TP\fCAlignTop\fR aligns to the top border..TP\fCAlignBottom\fR aligns to the bottom border..TP\fCAlignVCenter\fR aligns vertically centered.TP\fCAlignCenter\fR (= \fCAlignHCenter\fR | \fCAlignVCenter)\fR.TP\fCExpandTabs\fR expands tabulators..TP\fCWordBreak\fR enables automatic word breaking..PPIf the label has a buddy, \fCShowPrefix\fR is forced to TRUE..PPSee also: alignment(), setBuddy() and setText()..PPExamples:.(lcursor/cursor.cpp layout/layout.cpp popup/popup.cpp qmag/qmag.cpp customlayout/main.cpp.)l.SH "void QLabel::setAutoResize ( bool enable ) \fC[virtual]\fR"Enables auto-resizing if \fIenable\fR is TRUE, or disables it if \fIenable\fR is FALSE..PPWhen auto-resizing is enabled, the label will resize itself whenever the contents change. The top left corner is not moved..PPSee also: autoResize() and adjustSize()..SH "void QLabel::setBuddy ( QWidget * buddy ) \fC[virtual]\fR"Sets the buddy of this label to \fIbuddy.\fR.PPWhen the user presses the accelerator key indicated by this label, the keyboard focus is transferred to the label's buddy..PPSee also: label() and setText()..PPExamples:.(llayout/layout.cpp.)l.SH "void QLabel::setIndent ( int indent )"Sets the indent of the label to \fIindent\fR pixels..PPThe indent applies to the left edge if alignment() is \fCAlignLeft,\fR to the right edge if alignment() is \fCAlignRight,\fR to the top edge if alignment() is \fCAlignTop,\fR and to to the bottom edge if alignment() is \fCAlignBottom.\fR.PPIf \fIindent\fR is negative (as it is by default), the label computes the indent as follows: If the frame width is zero, the effective indent becomes 0. If the frame style is greater than zero, the effective indent becomes half the width of the "x" character (of the widget's current font..PPSetting a non-negative indent gives the specified indent in pixels..PPSee also: indent(), frameWidth() and font()..PPExamples:.(lmovies/main.cpp.)l.SH "void QLabel::setMovie ( const QMovie & movie ) \fC[virtual slot]\fR"Sets a QMovie to display in the label, or removes any existing movie if the given movie QMovie::isNull()..PPAny current pixmap or text label is cleared..PPIf the label has a buddy, the accelerator is disabled since the movie doesn't contain any suitable character..PPSee also: unsetMovie()..SH "void QLabel::setNum ( double num ) \fC[virtual slot]\fR"Sets the label contents to \fInum\fR (converts it to text) and redraws the contents..PPIf the label has a buddy, the accelerator is disabled since the number doesn't contain any suitable character..PPThe label resizes itself if auto-resizing is enabled..PPSee also: setAutoResize()..SH "void QLabel::setNum ( int num ) \fC[virtual slot]\fR"Sets the label contents to \fInum\fR (converts it to text) and redraws the contents..PPIf the label has a buddy, the accelerator is disabled since the number doesn't contain any suitable character..PPThe label resizes itself if auto-resizing is enabled. Nothing happens if \fInum\fR reads the same as the current label..PPSee also: setAutoResize()..SH "void QLabel::setPixmap ( const QPixmap & pixmap ) \fC[virtual slot]\fR"Sets the label contents to \fIpixmap\fR and redraws the contents..PPIf the label has a buddy, the accelerator is disabled since the pixmap doesn't contain any suitable character..PPThe label resizes itself if auto-resizing is enabled. Nothing happens if \fIpixmap\fR is the same as the current label..PPSee also: pixmap(), setText(), setTextFormat() and setAutoResize()..SH "void QLabel::setText ( const QString & text ) \fC[virtual slot]\fR"Sets the label contents to \fItext,\fR updates the optional accelerator and redraws the contents..PPThe label resizes itself if auto-resizing is enabled. Nothing happens if \fItext\fR is the same as the current label..PP\fItext\fR may be interpreted either as plain text or as rich text, depending on the textFormat(). The default setting is \fCAutoText,\fR i.e. the label autodetects the format from \fItext.\fR If the format is \fCRichText,\fR the label uses the default mime source factory to resolve references to images. See QMimeSourceFactory::defaultFactory() for details..PPNote that a label is only useful for rather small documents with one or maximal two lines of text. If you need to display larger documents, a QTextView is the widget of choice. It will flicker less on resize and can also provide a scrollbar if necessary..PPSee also: text(), setTextFormat(), setPixmap(), setAutoResize() and QTextView..PPExamples:.(lcursor/cursor.cpp layout/layout.cpp popup/popup.cpp qmag/qmag.cpp customlayout/main.cpp.)l.SH "void QLabel::setTextFormat ( Qt::TextFormat format )"Sets the text format to \fIformat.\fR Possible choices are.TP\fCPlainText\fR - all characters are displayed verbatimely, including all blanks and linebreaks. Word wrap is availbe with the \fCWordBreak\fR alignment flag (see setAlignment() for details)..TP\fCRichText\fR - rich text rendering. The available styles are defined in the default stylesheet QStyleSheet::defaultSheet()..TP\fCAutoText\fR - this is also the default. The label autodetects which rendering style suits best, \fCPlainText\fR or \fCRichText.\fR Technically, this is done by using the QStyleSheet::mightBeRichText() heuristic..SH "QSize QLabel::sizeHint () const \fC[virtual]\fR"Returns a size which fits the contents of the label..PPBugs and limitations:.TPDoes not work well with the WordBreak flag, use heightForWidth()..PPExamples:.(llayout/layout.cpp.)l.PPReimplemented from QWidget..SH "QSizePolicy QLabel::sizePolicy () const \fC[virtual]\fR"Specifies that this widget may stretch horizontally and vertically beyond the sizeHint()..PPReimplemented from QWidget..SH "QString QLabel::text () const"Returns the label text. This may be either plain text or a small rich text document..PPSee also: textFormat(), setText() and setTextFormat()..SH "Qt::TextFormat QLabel::textFormat() const"Returns the current text format..PPSee also: setTextFormat()..SH "SEE ALSO".BR http://www.troll.no/qt/qlabel.html.SH COPYRIGHTCopyright 1992-1999 Troll Tech AS. See the license file included inthe distribution for a complete license statement..SH AUTHORGenerated automatically from the source code.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -