使QLabel文本可选? [英] Make QLabel text selectable?
问题描述
我的应用程序中有一个 QLabel
,它向用户显示错误消息.我想选择标签的文本,以便用户可以根据需要复制和粘贴错误消息.
I have a QLabel
in my application that displays error messages to the user. I would like to make the text of the label selectable so users can copy and paste the error message if needed.
但是,当我使用鼠标单击并拖动文本时,什么也没有发生-未选择文本.
However, when I use the mouse to click and drag over the text, nothing happens - the text is not selected.
如何用鼠标选择 QLabel
中的文本?
How can I make the text within a QLabel
selectable by the mouse?
推荐答案
代码
通过鼠标可以选择 QLabel
的文本,如下所示:
The text of a QLabel
can be made selectable by mouse like so:
label->setTextInteractionFlags(Qt::TextSelectableByMouse);
可在 QLabel文档中找到.
您可以使用相同的功能通过键盘选择链接,突出显示URL链接,并使文本可编辑.参见 Qt :: TextInteractionFlag .
You can use that same function to make links selectable by keyboard, highlight URL links, and make the text editable. See Qt::TextInteractionFlag.
设计师
在 QLabel
菜单下搜索 textInteractionFlags
,然后设置标志 TextSelectableByMouse
.
Search for textInteractionFlags
under the QLabel
menu and set the flag TextSelectableByMouse
.
这篇关于使QLabel文本可选?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!