1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html><head><title>QLabel Class Reference</title><style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
td.postheader { font-family: sans-serif }
tr.address { font-family: sans-serif }
body { background: #ffffff; color: black; }
</style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr /><td align="left" valign="top" width="32"><img align="left" border="0" height="32" src="images/rb-logo.png" width="32" /></td><td width="1">  </td><td class="postheader" valign="center"><a href="../pyqt4ref.html"><font color="#004faf">Home</font></a> · <a href="classes.html"><font color="#004faf">All Classes</font></a> · <a href="modules.html"><font color="#004faf">Modules</font></a></td></table><h1 align="center">QLabel Class Reference<br /><sup><sup>[<a href="qtgui.html">QtGui</a> module]</sup></sup></h1><p>The QLabel widget provides a text or image display. <a href="#details">More...</a></p>
<p>Inherits <a href="qframe.html">QFrame</a>.</p><h3>Methods</h3><ul><li><div class="fn" /><b><a href="qlabel.html#QLabel">__init__</a></b> (<i>self</i>, QWidget <i>parent</i> = None, Qt.WindowFlags <i>f</i> = 0)</li><li><div class="fn" /><b><a href="qlabel.html#QLabel-2">__init__</a></b> (<i>self</i>, QString <i>text</i>, QWidget <i>parent</i> = None, Qt.WindowFlags <i>f</i> = 0)</li><li><div class="fn" />Qt.Alignment <b><a href="qlabel.html#alignment">alignment</a></b> (<i>self</i>)</li><li><div class="fn" />QWidget <b><a href="qlabel.html#buddy">buddy</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qlabel.html#changeEvent">changeEvent</a></b> (<i>self</i>, QEvent)</li><li><div class="fn" /><b><a href="qlabel.html#clear">clear</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qlabel.html#event">event</a></b> (<i>self</i>, QEvent <i>e</i>)</li><li><div class="fn" />bool <b><a href="qlabel.html#hasScaledContents">hasScaledContents</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qlabel.html#heightForWidth">heightForWidth</a></b> (<i>self</i>, int)</li><li><div class="fn" />int <b><a href="qlabel.html#indent">indent</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qlabel.html#margin">margin</a></b> (<i>self</i>)</li><li><div class="fn" />QSize <b><a href="qlabel.html#minimumSizeHint">minimumSizeHint</a></b> (<i>self</i>)</li><li><div class="fn" />QMovie <b><a href="qlabel.html#movie">movie</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qlabel.html#paintEvent">paintEvent</a></b> (<i>self</i>, QPaintEvent)</li><li><div class="fn" />QPicture <b><a href="qlabel.html#picture">picture</a></b> (<i>self</i>)</li><li><div class="fn" />QPixmap <b><a href="qlabel.html#pixmap">pixmap</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qlabel.html#setAlignment">setAlignment</a></b> (<i>self</i>, Qt.Alignment)</li><li><div class="fn" /><b><a href="qlabel.html#setBuddy">setBuddy</a></b> (<i>self</i>, QWidget)</li><li><div class="fn" /><b><a href="qlabel.html#setIndent">setIndent</a></b> (<i>self</i>, int)</li><li><div class="fn" /><b><a href="qlabel.html#setMargin">setMargin</a></b> (<i>self</i>, int)</li><li><div class="fn" /><b><a href="qlabel.html#setMovie">setMovie</a></b> (<i>self</i>, QMovie <i>movie</i>)</li><li><div class="fn" /><b><a href="qlabel.html#setNum">setNum</a></b> (<i>self</i>, float)</li><li><div class="fn" /><b><a href="qlabel.html#setNum-2">setNum</a></b> (<i>self</i>, int)</li><li><div class="fn" /><b><a href="qlabel.html#setPicture">setPicture</a></b> (<i>self</i>, QPicture)</li><li><div class="fn" /><b><a href="qlabel.html#setPixmap">setPixmap</a></b> (<i>self</i>, QPixmap)</li><li><div class="fn" /><b><a href="qlabel.html#setScaledContents">setScaledContents</a></b> (<i>self</i>, bool)</li><li><div class="fn" /><b><a href="qlabel.html#setText">setText</a></b> (<i>self</i>, QString)</li><li><div class="fn" /><b><a href="qlabel.html#setTextFormat">setTextFormat</a></b> (<i>self</i>, Qt.TextFormat)</li><li><div class="fn" /><b><a href="qlabel.html#setWordWrap">setWordWrap</a></b> (<i>self</i>, bool <i>on</i>)</li><li><div class="fn" />QSize <b><a href="qlabel.html#sizeHint">sizeHint</a></b> (<i>self</i>)</li><li><div class="fn" />QString <b><a href="qlabel.html#text">text</a></b> (<i>self</i>)</li><li><div class="fn" />Qt.TextFormat <b><a href="qlabel.html#textFormat">textFormat</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qlabel.html#wordWrap">wordWrap</a></b> (<i>self</i>)</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QLabel widget provides a text or image display.</p>
<p>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.</p>
<p>A QLabel can contain any of the following content types:</p>
<table align="center" border="0" cellpadding="2" cellspacing="1">
<tr bgcolor="#A2C511" valign="top">
<th>Content</th>
<th>Setting</th>
</tr>
<tr bgcolor="#F0F0F0" valign="top">
<td>Plain text</td>
<td>Pass a <a href="qstring.html">QString</a> to <a href="qlabel.html#text-prop">setText</a>().</td>
</tr>
<tr bgcolor="#E0E0E0" valign="top">
<td>Rich text</td>
<td>Pass a <a href="qstring.html">QString</a> that contains rich text to <a href="qlabel.html#text-prop">setText</a>().</td>
</tr>
<tr bgcolor="#F0F0F0" valign="top">
<td>A pixmap</td>
<td>Pass a <a href="qpixmap.html">QPixmap</a> to <a href="qlabel.html#pixmap-prop">setPixmap</a>().</td>
</tr>
<tr bgcolor="#E0E0E0" valign="top">
<td>A movie</td>
<td>Pass a <a href="qmovie.html">QMovie</a> to <a href="qlabel.html#setMovie">setMovie</a>().</td>
</tr>
<tr bgcolor="#F0F0F0" valign="top">
<td>A number</td>
<td>Pass an <i>int</i> or a <i>double</i> to <a href="qlabel.html#setNum">setNum</a>(), which converts the number to plain text.</td>
</tr>
<tr bgcolor="#E0E0E0" valign="top">
<td>Nothing</td>
<td>The same as an empty plain text. This is the default. Set by <a href="qlabel.html#clear">clear</a>().</td>
</tr>
</table>
<br />
<br />
<p>When the content is changed using any of these functions, any previous content is cleared.</p>
<p>The look of a QLabel can be tuned in several ways. All the settings of <a href="qframe.html">QFrame</a> are available for specifying a widget frame. The positioning of the content within the QLabel widget area can be tuned with <a href="qlabel.html#alignment-prop">setAlignment</a>() and <a href="qlabel.html#indent-prop">setIndent</a>(). Text content can also wrap lines along word bounderies with <a href="qlabel.html#wordWrap-prop">setWordWrap</a>(). 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):</p>
<pre>
QLabel *label = new QLabel(this);
label->setFrameStyle(QFrame.Panel | QFrame.Sunken);
label->setText("first line\nsecond line");
label->setAlignment(Qt.AlignBottom | Qt.AlignRight);
</pre>
<p>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:</p>
<pre>
QLineEdit* phoneEdit = new QLineEdit(this);
QLabel* phoneLabel = new QLabel("&Phone:", this);
phoneLabel->setBuddy(phoneEdit);
</pre>
<p>In this example, keyboard focus is transferred to the label's buddy (the <a href="qlineedit.html">QLineEdit</a>) when the user presses Alt+P. If the buddy was a button (inheriting from <a href="qabstractbutton.html">QAbstractButton</a>), triggering the mnemonic would emulate a button click.</p>
<table align="center" border="0" cellpadding="2" cellspacing="1" width="100%">
<tr bgcolor="#F0F0F0" valign="top">
<td><img alt="Screenshot of a Macintosh style label" src="images/macintosh-label.png" /></td>
<td>A label shown in the <a href="gallery-macintosh.html">Macintosh widget style</a>.</td>
</tr>
<tr bgcolor="#E0E0E0" valign="top">
<td><img alt="Screenshot of a Plastique style label" src="images/plastique-label.png" /></td>
<td>A label shown in the <a href="gallery-plastique.html">Plastique widget style</a>.</td>
</tr>
<tr bgcolor="#F0F0F0" valign="top">
<td><img alt="Screenshot of a Windows XP style label" src="images/windowsxp-label.png" /></td>
<td>A label shown in the <a href="gallery-windowsxp.html">Windows XP widget style</a>.</td>
</tr>
</table>
<br />
<br />
<p>See also <a href="qlineedit.html">QLineEdit</a>, <a href="qtextedit.html">QTextEdit</a>, <a href="qpixmap.html">QPixmap</a>, <a href="qmovie.html">QMovie</a>, and <a href="guibooks.html#fowler">GUI Design Handbook: Label</a>.</p>
<hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QLabel" />QLabel.__init__ (<i>self</i>, <a href="qwidget.html">QWidget</a> <i>parent</i> = None, <a href="qt-windowflags.html">Qt.WindowFlags</a> <i>f</i> = 0)</h3><p>The <i>parent</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt.</p><p>Constructs an empty label.</p>
<p>The <i>parent</i> and widget flag <i>f</i>, arguments are passed to the <a href="qframe.html">QFrame</a> constructor.</p>
<p>See also <a href="qlabel.html#alignment-prop">setAlignment</a>(), <a href="qframe.html#setFrameStyle">setFrameStyle</a>(), and <a href="qlabel.html#indent-prop">setIndent</a>().</p>
<h3 class="fn"><a name="QLabel-2" />QLabel.__init__ (<i>self</i>, <a href="qstring.html">QString</a> <i>text</i>, <a href="qwidget.html">QWidget</a> <i>parent</i> = None, <a href="qt-windowflags.html">Qt.WindowFlags</a> <i>f</i> = 0)</h3><p>The <i>parent</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt.</p><p>Constructs a label that displays the text, <i>text</i>.</p>
<p>The <i>parent</i> and widget flag <i>f</i>, arguments are passed to the <a href="qframe.html">QFrame</a> constructor.</p>
<p>See also <a href="qlabel.html#text-prop">setText</a>(), <a href="qlabel.html#alignment-prop">setAlignment</a>(), <a href="qframe.html#setFrameStyle">setFrameStyle</a>(), and <a href="qlabel.html#indent-prop">setIndent</a>().</p>
<h3 class="fn"><a name="alignment" /><a href="qt-alignment.html">Qt.Alignment</a> QLabel.alignment (<i>self</i>)</h3><h3 class="fn"><a name="buddy" /><a href="qwidget.html">QWidget</a> QLabel.buddy (<i>self</i>)</h3><p>Returns this label's buddy, or 0 if no buddy is currently set.</p>
<p>See also <a href="qlabel.html#setBuddy">setBuddy</a>().</p>
<h3 class="fn"><a name="changeEvent" />QLabel.changeEvent (<i>self</i>, <a href="qevent.html">QEvent</a>)</h3><h3 class="fn"><a name="clear" />QLabel.clear (<i>self</i>)</h3><p>Clears any label contents.</p>
<h3 class="fn"><a name="event" />bool QLabel.event (<i>self</i>, <a href="qevent.html">QEvent</a> <i>e</i>)</h3><h3 class="fn"><a name="hasScaledContents" />bool QLabel.hasScaledContents (<i>self</i>)</h3><h3 class="fn"><a name="heightForWidth" />int QLabel.heightForWidth (<i>self</i>, int)</h3><h3 class="fn"><a name="indent" />int QLabel.indent (<i>self</i>)</h3><h3 class="fn"><a name="margin" />int QLabel.margin (<i>self</i>)</h3><h3 class="fn"><a name="minimumSizeHint" /><a href="qsize.html">QSize</a> QLabel.minimumSizeHint (<i>self</i>)</h3><h3 class="fn"><a name="movie" /><a href="qmovie.html">QMovie</a> QLabel.movie (<i>self</i>)</h3><p>Returns a pointer to the label's movie, or 0 if no movie has been set.</p>
<p>See also <a href="qlabel.html#setMovie">setMovie</a>().</p>
<h3 class="fn"><a name="paintEvent" />QLabel.paintEvent (<i>self</i>, <a href="qpaintevent.html">QPaintEvent</a>)</h3><h3 class="fn"><a name="picture" /><a href="qpicture.html">QPicture</a> QLabel.picture (<i>self</i>)</h3><p>Returns the label's picture or 0 if the label doesn't have a picture.</p>
<p>See also <a href="qlabel.html#setPicture">setPicture</a>().</p>
<h3 class="fn"><a name="pixmap" /><a href="qpixmap.html">QPixmap</a> QLabel.pixmap (<i>self</i>)</h3><h3 class="fn"><a name="setAlignment" />QLabel.setAlignment (<i>self</i>, <a href="qt-alignment.html">Qt.Alignment</a>)</h3><h3 class="fn"><a name="setBuddy" />QLabel.setBuddy (<i>self</i>, <a href="qwidget.html">QWidget</a>)</h3><p>Sets this label's buddy to <i>buddy</i>.</p>
<p>When the user presses the shortcut key indicated by this label, the keyboard focus is transferred to the label's buddy widget.</p>
<p>The buddy mechanism is only available for QLabels that contain plain text in which one letter is prefixed with an ampersand, &. This letter is set as the shortcut key. The letter is displayed underlined, and the '&' is not displayed (i.e. the <a href="qt.html#TextFlag-enum">Qt.TextShowMnemonic</a> alignment flag is turned on; see <a href="qlabel.html#alignment-prop">setAlignment</a>()).</p>
<p>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:</p>
<pre>
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)
</pre>
<p>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.</p>
<p>To unset a previously set buddy, call this function with <i>buddy</i> set to 0.</p>
<p>See also <a href="qlabel.html#buddy">buddy</a>(), <a href="qlabel.html#text-prop">setText</a>(), <a href="qshortcut.html">QShortcut</a>, and <a href="qlabel.html#alignment-prop">setAlignment</a>().</p>
<h3 class="fn"><a name="setIndent" />QLabel.setIndent (<i>self</i>, int)</h3><h3 class="fn"><a name="setMargin" />QLabel.setMargin (<i>self</i>, int)</h3><h3 class="fn"><a name="setMovie" />QLabel.setMovie (<i>self</i>, <a href="qmovie.html">QMovie</a> <i>movie</i>)</h3><p>Sets the label contents to <i>movie</i>. Any previous content is cleared.</p>
<p>The buddy shortcut, if any, is disabled.</p>
<p>The label resizes itself if auto-resizing is enabled.</p>
<p>See also <a href="qlabel.html#movie">movie</a>() and <a href="qlabel.html#setBuddy">setBuddy</a>().</p>
<h3 class="fn"><a name="setNum" />QLabel.setNum (<i>self</i>, float)</h3><p>Sets the label contents to plain text containing the textual representation of integer <i>num</i>. Any previous content is cleared. Does nothing if the integer's string representation is the same as the current contents of the label.</p>
<p>The buddy shortcut, if any, is disabled.</p>
<p>The label resizes itself if auto-resizing is enabled.</p>
<p>See also <a href="qlabel.html#text-prop">setText</a>(), <a href="qstring.html#setNum">QString.setNum</a>(), and <a href="qlabel.html#setBuddy">setBuddy</a>().</p>
<h3 class="fn"><a name="setNum-2" />QLabel.setNum (<i>self</i>, int)</h3><p>This is an overloaded member function, provided for convenience.</p>
<p>Sets the label contents to plain text containing the textual representation of double <i>num</i>. Any previous content is cleared. Does nothing if the double's string representation is the same as the current contents of the label.</p>
<p>The buddy shortcut, if any, is disabled.</p>
<p>The label resizes itself if auto-resizing is enabled.</p>
<p>See also <a href="qlabel.html#text-prop">setText</a>(), <a href="qstring.html#setNum">QString.setNum</a>(), and <a href="qlabel.html#setBuddy">setBuddy</a>().</p>
<h3 class="fn"><a name="setPicture" />QLabel.setPicture (<i>self</i>, <a href="qpicture.html">QPicture</a>)</h3><p>Sets the label contents to <i>picture</i>. Any previous content is cleared.</p>
<p>The buddy shortcut, if any, is disabled.</p>
<p>See also <a href="qlabel.html#picture">picture</a>() and <a href="qlabel.html#setBuddy">setBuddy</a>().</p>
<h3 class="fn"><a name="setPixmap" />QLabel.setPixmap (<i>self</i>, <a href="qpixmap.html">QPixmap</a>)</h3><h3 class="fn"><a name="setScaledContents" />QLabel.setScaledContents (<i>self</i>, bool)</h3><h3 class="fn"><a name="setText" />QLabel.setText (<i>self</i>, <a href="qstring.html">QString</a>)</h3><h3 class="fn"><a name="setTextFormat" />QLabel.setTextFormat (<i>self</i>, <a href="qt.html#TextFormat-enum">Qt.TextFormat</a>)</h3><h3 class="fn"><a name="setWordWrap" />QLabel.setWordWrap (<i>self</i>, bool <i>on</i>)</h3><h3 class="fn"><a name="sizeHint" /><a href="qsize.html">QSize</a> QLabel.sizeHint (<i>self</i>)</h3><h3 class="fn"><a name="text" /><a href="qstring.html">QString</a> QLabel.text (<i>self</i>)</h3><h3 class="fn"><a name="textFormat" /><a href="qt.html#TextFormat-enum">Qt.TextFormat</a> QLabel.textFormat (<i>self</i>)</h3><h3 class="fn"><a name="wordWrap" />bool QLabel.wordWrap (<i>self</i>)</h3><address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td width="25%">PyQt 4.0.1 for X11</td><td align="center" width="50%">Copyright © <a href="http://www.riverbankcomputing.com">Riverbank Computing Ltd</a> and <a href="http://www.trolltech.com">Trolltech AS</a> 2006</td><td align="right" width="25%">Qt 4.1.4</td></tr></table></div></address></body></html>
|