Qt Widgets Designer好友编辑模式
Qt 最有用的基本功能之一是支持好友部件。当用户键入标签的快捷键组合时,好友部件代表QLabel 接受输入焦点。Qt 的模型/视图框架中也使用了好友概念。
将标签链接到好友部件
要进入好友编辑模式,请打开 "编辑"菜单并选择 "编辑好友"。该模式在表单上显示部件的方式与信号和槽编辑模式类似,但在该模式下,连接必须从标签部件开始。理想情况下,应将每个提供快捷方式的标签部件与合适的输入部件连接起来,如QLineEdit 。
![]() | 创建好友 要为标签定义一个好友部件,请单击标签,将连接拖动到表单上的另一个部件,然后松开鼠标按钮。显示的连接表示如何将输入焦点传递给好友部件。您可以使用表单预览来测试每个标签与其好友之间的连接。 |
删除好友连接
每个标签只能定义一个好友部件。要更改使用的好友,必须先删除任何现有的好友连接,然后再创建新的好友连接。
标签与其好友部件之间的连接删除方式与信号和槽编辑模式下的信号槽连接相同:单击好友连接并按下删除键。该操作不会以任何方式修改标签或其好友。
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.