PySide.QtGui.QLabel widget provides a text or image display.
PySide.QtGui.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 PySide.QtGui.QLabel can contain any of the following content types:
| 内容 | 设置 |
| 纯文本 | 传递 PySide.QtCore.QString to PySide.QtGui.QLabel.setText() . |
| 富文本 | 传递 PySide.QtCore.QString 包含富文本到 PySide.QtGui.QLabel.setText() . |
| 像素图 | 传递 PySide.QtGui.QPixmap to PySide.QtGui.QLabel.setPixmap() . |
| 影片 | 传递 PySide.QtGui.QMovie to PySide.QtGui.QLabel.setMovie() . |
| 数字 | 传递 int 或 double to PySide.QtGui.QLabel.setNum() , which converts the number to plain text. |
| 什么都没有 | 如同空纯文本。这是默认。设置通过 PySide.QtGui.QLabel.clear() . |
警告
当传递 PySide.QtCore.QString 到构造函数或调用 PySide.QtGui.QLabel.setText() , make sure to sanitize your input, as PySide.QtGui.QLabel tries to guess whether it displays the text as plain text or as rich text. You may want to call PySide.QtGui.QLabel.setTextFormat() explicitly, e.g. in case you expect the text to be in plain format but cannot control the text source (for instance when displaying data loaded from the Web).
当使用这些函数中的任一改变内容时,任何先前内容被清零。
默认情况下,标签显示 left-aligned, vertically-centered 文本和图像,要显示文本中的任何 Tab 都会 automatically expanded . However, the look of a PySide.QtGui.QLabel can be adjusted and fine-tuned in several ways.
The positioning of the content within the PySide.QtGui.QLabel widget area can be tuned with PySide.QtGui.QLabel.setAlignment() and PySide.QtGui.QLabel.setIndent() . Text content can also wrap lines along word boundaries with PySide.QtGui.QLabel.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):
label = QLabel(self)
label.setFrameStyle(QFrame.Panel | QFrame.Sunken)
label.setText("first line\nsecond line")
label.setAlignment(Qt.AlignBottom | Qt.AlignRight)
The properties and functions PySide.QtGui.QLabel 继承自 PySide.QtGui.QFrame 还可以用于指定要用于任何给定标签的 Widget 框架。
A PySide.QtGui.QLabel is often used as a label for an interactive widget. For this use PySide.QtGui.QLabel provides a useful mechanism for adding an mnemonic (see PySide.QtGui.QKeySequence ) that will set the keyboard focus to the other widget (called the PySide.QtGui.QLabel ‘s “buddy”). For example:
phoneEdit = QLineEdit(self)
phoneLabel = QLabel("&Phone:", self)
phoneLabel.setBuddy(phoneEdit)
在此范例中,键盘焦点被转移给标签好友 ( PySide.QtGui.QLineEdit ) 当用户按下 Alt+P 键时。若好友是按钮 (继承自 PySide.QtGui.QAbstractButton ),触发助记键将模拟按钮点击。
|
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 . |
| 参数: |
|
|---|
| 返回类型: | PySide.QtCore.Qt.Alignment |
|---|
This property holds the alignment of the label's contents.
默认情况下,标签内容左对齐且垂直居中。
| 返回类型: | PySide.QtGui.QWidget |
|---|
Returns this label's buddy, or 0 if no buddy is currently set.
清零任何标签内容。
| 返回类型: | PySide.QtCore.bool |
|---|
This property holds whether the label will scale its contents to fill all available space..
当启用且标签展示像素图时,它将比例缩放像素图以填充可用空间。
此特性默认为 false。
| 返回类型: | PySide.QtCore.bool |
|---|
此特性保持是否有选中任何文本。
PySide.QtGui.QLabel.hasSelectedText() returns true if some or all of the text has been selected by the user; otherwise returns false.
默认情况下,此特性为 false。
注意
PySide.QtGui.QLabel.textInteractionFlags() 设置标签需要包括 TextSelectableByMouse 或 TextSelectableByKeyboard。
| 返回类型: | PySide.QtCore.int |
|---|
This property holds the label's text indent in pixels.
若标签显示文本,缩进被应用到左边缘,若 PySide.QtGui.QLabel.alignment() is Qt.AlignLeft ,到右边缘若 PySide.QtGui.QLabel.alignment() is Qt.AlignRight ,到上边缘若 PySide.QtGui.QLabel.alignment() is Qt.AlignTop , and to to the bottom edge if PySide.QtGui.QLabel.alignment() is Qt.AlignBottom .
若缩进为负数或未设置缩进,标签将计算有效缩进,如下所示:若 PySide.QtGui.QFrame.frameWidth() is 0, the effective indent becomes 0. If PySide.QtGui.QFrame.frameWidth() is greater than 0, the effective indent becomes half the width of the “x” character of the widget's current PySide.QtGui.QWidget.font() .
默认情况下,缩进为 -1,意味着有效缩进按上述方式计算。
| 参数: | link – unicode |
|---|
| 参数: | link – unicode |
|---|
| 返回类型: | PySide.QtCore.int |
|---|
This property holds the width of the margin.
边距是框架最内像素和内容最外像素之间的距离。
默认边距为 0。
| 返回类型: | PySide.QtGui.QMovie |
|---|
Returns a pointer to the label's movie, or 0 if no movie has been set.
| 返回类型: | PySide.QtCore.bool |
|---|
指定是否 PySide.QtGui.QLabel 应自动打开链接使用 QDesktopServices.openUrl() instead of emitting the PySide.QtGui.QLabel.linkActivated() 信号。
注意
PySide.QtGui.QLabel.textInteractionFlags() 在标签上设置需要包括 LinksAccessibleByMouse 或 LinksAccessibleByKeyboard。
默认值为 false。
| 返回类型: | PySide.QtGui.QPicture |
|---|
Returns the label's picture or 0 if the label doesn't have a picture.
| 返回类型: | PySide.QtGui.QPixmap |
|---|
此特性保持标签的像素图。
If no pixmap has been set this will return 0.
设置像素图会清零任何之前内容。好友快捷方式 (若有的话) 被禁用。
| 返回类型: | unicode |
|---|
此特性保持选中文本。
若没有选中文本,此特性的值为空字符串。
默认情况下,此特性包含空字符串。
注意
PySide.QtGui.QLabel.textInteractionFlags() 设置标签需要包括 TextSelectableByMouse 或 TextSelectableByKeyboard。
| 返回类型: | PySide.QtCore.int |
|---|
PySide.QtGui.QLabel.selectionStart() returns the index of the first selected character in the label or -1 if no text is selected.
注意
PySide.QtGui.QLabel.textInteractionFlags() 设置标签需要包括 TextSelectableByMouse 或 TextSelectableByKeyboard。
| 参数: | arg__1 – PySide.QtCore.Qt.Alignment |
|---|
This property holds the alignment of the label's contents.
默认情况下,标签内容左对齐且垂直居中。
| 参数: | arg__1 – PySide.QtGui.QWidget |
|---|
将此标签的好友设为 buddy .
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:
nameEd = QLineEdit(self)
nameLb = QLabel("&Name:", self)
nameLb.setBuddy(nameEd)
phoneEd = QLineEdit(self)
phoneLb = QLabel("&Phone:", self)
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.
要取消先前设置的好友,调用此函数采用 buddy set to 0.
| 参数: | arg__1 – PySide.QtCore.int |
|---|
This property holds the label's text indent in pixels.
若标签显示文本,缩进被应用到左边缘,若 PySide.QtGui.QLabel.alignment() is Qt.AlignLeft ,到右边缘若 PySide.QtGui.QLabel.alignment() is Qt.AlignRight ,到上边缘若 PySide.QtGui.QLabel.alignment() is Qt.AlignTop , and to to the bottom edge if PySide.QtGui.QLabel.alignment() is Qt.AlignBottom .
若缩进为负数或未设置缩进,标签将计算有效缩进,如下所示:若 PySide.QtGui.QFrame.frameWidth() is 0, the effective indent becomes 0. If PySide.QtGui.QFrame.frameWidth() is greater than 0, the effective indent becomes half the width of the “x” character of the widget's current PySide.QtGui.QWidget.font() .
默认情况下,缩进为 -1,意味着有效缩进按上述方式计算。
| 参数: | arg__1 – PySide.QtCore.int |
|---|
This property holds the width of the margin.
边距是框架最内像素和内容最外像素之间的距离。
默认边距为 0。
| 参数: | movie – PySide.QtGui.QMovie |
|---|
将标签内容设为 movie . Any previous content is cleared. The label does NOT take ownership of the movie.
好友快捷方式 (若有的话) 被禁用。
| 参数: | arg__1 – PySide.QtCore.double |
|---|
这是重载函数。
Sets the label contents to plain text containing the textual representation of double num . Any previous content is cleared. Does nothing if the double's string representation is the same as the current contents of the label.
好友快捷方式 (若有的话) 被禁用。
另请参阅
PySide.QtGui.QLabel.setText() QString.setNum() PySide.QtGui.QLabel.setBuddy()
| 参数: | arg__1 – PySide.QtCore.int |
|---|
Sets the label contents to plain text containing the textual representation of integer num . Any previous content is cleared. Does nothing if the integer's string representation is the same as the current contents of the label.
好友快捷方式 (若有的话) 被禁用。
另请参阅
PySide.QtGui.QLabel.setText() QString.setNum() PySide.QtGui.QLabel.setBuddy()
| 参数: | open – PySide.QtCore.bool |
|---|
指定是否 PySide.QtGui.QLabel 应自动打开链接使用 QDesktopServices.openUrl() instead of emitting the PySide.QtGui.QLabel.linkActivated() 信号。
注意
PySide.QtGui.QLabel.textInteractionFlags() 在标签上设置需要包括 LinksAccessibleByMouse 或 LinksAccessibleByKeyboard。
默认值为 false。
| 参数: | arg__1 – PySide.QtGui.QPicture |
|---|
将标签内容设为 picture 。任何先前内容被清零。
好友快捷方式 (若有的话) 被禁用。
| 参数: | arg__1 – PySide.QtGui.QPixmap |
|---|
此特性保持标签的像素图。
If no pixmap has been set this will return 0.
设置像素图会清零任何之前内容。好友快捷方式 (若有的话) 被禁用。
| 参数: | arg__1 – PySide.QtCore.bool |
|---|
This property holds whether the label will scale its contents to fill all available space..
当启用且标签展示像素图时,它将比例缩放像素图以填充可用空间。
此特性默认为 false。
| 参数: |
|
|---|
选择文本从位置 start 和对于 length 字符。
注意
PySide.QtGui.QLabel.textInteractionFlags() 设置标签需要包括 TextSelectableByMouse 或 TextSelectableByKeyboard。
| 参数: | arg__1 – unicode |
|---|
This property holds 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 PySide.QtGui.QLabel.setTextFormat() . The default setting is Qt.AutoText ; i.e. PySide.QtGui.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.
注意: PySide.QtGui.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 PySide.QtGui.QTextEdit in read-only mode instead. PySide.QtGui.QTextEdit can also provide a scroll bar when necessary.
注意
此函数启用鼠标跟踪若 text 包含富文本。
| 参数: | arg__1 – PySide.QtCore.Qt.TextFormat |
|---|
This property holds the label's text format.
见 Qt.TextFormat 枚举了解可能选项的解释。
默认格式为 Qt.AutoText .
| 参数: | flags – PySide.QtCore.Qt.TextInteractionFlags |
|---|
指定标签应如何与用户输入交互,若它显示文本。
若标志包含 Qt.LinksAccessibleByKeyboard 聚焦策略还被自动设为 Qt.StrongFocus 。若 Qt.TextSelectableByKeyboard 有设置那么聚焦策略被设为 Qt.ClickFocus .
默认值为 Qt.LinksAccessibleByMouse .
| 参数: | on – PySide.QtCore.bool |
|---|
This property holds 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.
默认情况下,自动换行是禁用的。
| 返回类型: | unicode |
|---|
This property holds 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 PySide.QtGui.QLabel.setTextFormat() . The default setting is Qt.AutoText ; i.e. PySide.QtGui.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.
注意: PySide.QtGui.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 PySide.QtGui.QTextEdit in read-only mode instead. PySide.QtGui.QTextEdit can also provide a scroll bar when necessary.
注意
此函数启用鼠标跟踪若 text 包含富文本。
| 返回类型: | PySide.QtCore.Qt.TextFormat |
|---|
This property holds the label's text format.
见 Qt.TextFormat 枚举了解可能选项的解释。
默认格式为 Qt.AutoText .
| 返回类型: | PySide.QtCore.Qt.TextInteractionFlags |
|---|
指定标签应如何与用户输入交互,若它显示文本。
若标志包含 Qt.LinksAccessibleByKeyboard 聚焦策略还被自动设为 Qt.StrongFocus 。若 Qt.TextSelectableByKeyboard 有设置那么聚焦策略被设为 Qt.ClickFocus .
默认值为 Qt.LinksAccessibleByMouse .
| 返回类型: | PySide.QtCore.bool |
|---|
This property holds 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.
默认情况下,自动换行是禁用的。