def
alignment
()
def
buddy
()
def
hasScaledContents
()
def
hasSelectedText
()
def
indent
()
def
margin
()
def
movie
()
def
openExternalLinks
()
def
picture
()
def
pixmap
()
def
selectedText
()
def
selectionStart
()
def
setAlignment
(arg__1)
def
setBuddy
(arg__1)
def
setIndent
(arg__1)
def
setMargin
(arg__1)
def
setOpenExternalLinks
(open)
def
setScaledContents
(arg__1)
def
setSelection
(arg__1, arg__2)
def
setTextFormat
(arg__1)
def
setTextInteractionFlags
(flags)
def
setWordWrap
(on)
def
text
()
def
textFormat
()
def
textInteractionFlags
()
def
wordWrap
()
def
linkActivated
(link)
def
linkHovered
(link)
![]()
QLabelis 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
QLabelcan contain any of the following content types:
内容
设置
纯文本
传递
QStringtosetText().富文本
传递
QString包含富文本到setText().像素图
传递
QPixmaptosetPixmap().影片
传递
QMovietosetMovie().数字
传递 int 或 double to
setNum(), which converts the number to plain text.什么都没有
如同空纯文本。这是默认。设置通过
clear().警告
当传递
QString到构造函数或调用setText(), make sure to sanitize your input, asQLabeltries to guess whether it displays the text as plain text or as rich text, a subset of HTML 4 markup. You may want to callsetTextFormat()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).当使用这些函数中的任一改变内容时,任何先前内容被清零。
默认情况下,标签显示 左对齐,垂直居中 文本和图像,要显示文本中的任何 Tab 都会
automatically expanded. However, the look of aQLabelcan be adjusted and fine-tuned in several ways.The positioning of the content within the
QLabelwidget area can be tuned withsetAlignment()andsetIndent(). Text content can also wrap lines along word boundaries withsetWordWrap(). 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
QLabel继承自QFrame还可以用于指定要用于任何给定标签的 Widget 框架。A
QLabelis often used as a label for an interactive widget. For this useQLabelprovides a useful mechanism for adding an mnemonic (seeQKeySequence) that will set the keyboard focus to the other widget (called theQLabel‘s “buddy”). For example:phoneEdit = QLineEdit(self) phoneLabel = QLabel("&Phone:", self) phoneLabel.setBuddy(phoneEdit)In this example, keyboard focus is transferred to the label’s buddy (the
QLineEdit) 当用户按下 Alt+P 键时。若好友是按钮 (继承自QAbstractButton),触发助记键将模拟按钮点击。
QLabel
(
[
parent=None
[
,
f=Qt.WindowFlags()
]
]
)
¶
QLabel(text[, parent=None[, f=Qt.WindowFlags()]])
- param f
WindowFlags- param parent
- param text
unicode
构造空标签。
parent
和 Widget 标志
f
,自变量被传递给
QFrame
构造函数。
构造标签显示文本
text
.
parent
和 Widget 标志
f
,自变量被传递给
QFrame
构造函数。
PySide2.QtWidgets.QLabel.
alignment
(
)
¶
Alignment
另请参阅
PySide2.QtWidgets.QLabel.
buddy
(
)
¶
Returns this label’s buddy, or nullptr if no buddy is currently set.
另请参阅
PySide2.QtWidgets.QLabel.
clear
(
)
¶
清零任何标签内容。
PySide2.QtWidgets.QLabel.
hasScaledContents
(
)
¶
bool
PySide2.QtWidgets.QLabel.
hasSelectedText
(
)
¶
bool
PySide2.QtWidgets.QLabel.
indent
(
)
¶
int
另请参阅
PySide2.QtWidgets.QLabel.
linkActivated
(
link
)
¶
link – unicode
PySide2.QtWidgets.QLabel.
linkHovered
(
link
)
¶
link – unicode
PySide2.QtWidgets.QLabel.
margin
(
)
¶
int
另请参阅
PySide2.QtWidgets.QLabel.
movie
(
)
¶
QMovie
Returns a pointer to the label’s movie, or nullptr if no movie has been set.
另请参阅
PySide2.QtWidgets.QLabel.
openExternalLinks
(
)
¶
bool
PySide2.QtWidgets.QLabel.
picture
(
)
¶
QPicture
注意
此函数被弃用。
New code should use the other overload which returns
QPicture
by-value.
This function returns the label’s picture or
nullptr
if the label doesn’t have a picture.
另请参阅
PySide2.QtWidgets.QLabel.
pixmap
(
)
¶
QPixmap
注意
此函数被弃用。
New code should use the other overload which returns
QPixmap
by-value.
另请参阅
PySide2.QtWidgets.QLabel.
selectedText
(
)
¶
unicode
PySide2.QtWidgets.QLabel.
selectionStart
(
)
¶
int
returns the index of the first selected character in the label or -1 if no text is selected.
注意
textInteractionFlags
设置标签需要包括 TextSelectableByMouse 或 TextSelectableByKeyboard。
另请参阅
PySide2.QtWidgets.QLabel.
setAlignment
(
arg__1
)
¶
arg__1
–
Alignment
另请参阅
PySide2.QtWidgets.QLabel.
setBuddy
(
arg__1
)
¶
arg__1
–
QWidget
Sets this label’s buddy to
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
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
设为 nullptr。
PySide2.QtWidgets.QLabel.
setMovie
(
movie
)
¶
movie
–
QMovie
将标签内容设为
movie
. Any previous content is cleared. The label does NOT take ownership of the movie.
好友快捷方式 (若有的话) 被禁用。
另请参阅
PySide2.QtWidgets.QLabel.
setNum
(
arg__1
)
¶
arg__1
–
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.
好友快捷方式 (若有的话) 被禁用。
另请参阅
setText()
setNum()
setBuddy()
PySide2.QtWidgets.QLabel.
setNum
(
arg__1
)
¶
arg__1
–
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.
好友快捷方式 (若有的话) 被禁用。
另请参阅
setText()
setNum()
setBuddy()
PySide2.QtWidgets.QLabel.
setOpenExternalLinks
(
open
)
¶
open
–
bool
另请参阅
PySide2.QtWidgets.QLabel.
setPicture
(
arg__1
)
¶
arg__1
–
QPicture
将标签内容设为
picture
。任何先前内容被清零。
好友快捷方式 (若有的话) 被禁用。
另请参阅
PySide2.QtWidgets.QLabel.
setScaledContents
(
arg__1
)
¶
arg__1
–
bool
另请参阅
PySide2.QtWidgets.QLabel.
setSelection
(
arg__1
,
arg__2
)
¶
arg__1
–
int
arg__2
–
int
选择文本从位置
start
和对于
length
字符。
注意
textInteractionFlags
设置标签需要包括 TextSelectableByMouse 或 TextSelectableByKeyboard。
另请参阅
PySide2.QtWidgets.QLabel.
setTextFormat
(
arg__1
)
¶
arg__1
–
TextFormat
另请参阅
PySide2.QtWidgets.QLabel.
setTextInteractionFlags
(
flags
)
¶
flags
–
TextInteractionFlags
PySide2.QtWidgets.QLabel.
setWordWrap
(
on
)
¶
on
–
bool
另请参阅
PySide2.QtWidgets.QLabel.
textFormat
(
)
¶
TextFormat
另请参阅
PySide2.QtWidgets.QLabel.
textInteractionFlags
(
)
¶
TextInteractionFlags
PySide2.QtWidgets.QLabel.
wordWrap
(
)
¶
bool
另请参阅