行为
要为不包含 C++ 或 QML 代码的文本文件(例如 Python 代码文件)指定缩进偏好设置,请选择“Preferences ”>“Text Editor ”>“Behavior ”。

您可以指定如何解释Tab和Backspace键的按键操作,以及如何对齐续行。
指定制表符首选项
您可以在以下级别指定制表符首选项:
- 针对所有 C++ 文件
- 针对所有 QML 文件
- 针对所有其他文本文件
- 针对项目中的 C++ 文件
- 针对项目中的 QML 文件
- 针对项目中的其他文本文件
指定制表符和缩进
您可以在“Tabs and Indentation ”组中指定制表符策略和制表符长度。在“Default Tab policy ”字段中,选择仅使用空格、仅使用制表符,还是混合使用两者进行缩进。
默认情况下,代码编辑器中的制表符长度为 8 个空格,缩进大小为 4 个空格。您可以针对每个项目以及不同类型的文件分别指定制表符长度和缩进大小。
您可以让续行与上一行对齐。在“续行对齐方式”(Align continuation lines )字段中,选择“不自动对齐”(Not at all )以禁用自动对齐,并将续行缩进至逻辑深度。若要始终使用空格进行对齐,请选择“使用空格对齐”(With Spaces )。若要遵循“代码风格指南”(Tab policy ),请选择“使用制表符对齐”(With Regular Indent )。
设置输入偏好
输入文本或代码时,系统会根据所选的文本编辑器或代码样式首选项自动进行缩进。要设置输入首选项,请选择“Preferences ” > “Text Editor ” > “Behavior ” > “Typing ”。
下表介绍了您可以设置的输入偏好设置。
| 首选项 | 描述 |
|---|---|
| Enable automatic indentation | 根据文本编辑器或代码样式首选项自动对新行进行缩进。 |
| Backspace indentation | 指定在选择“Backspace ”时缩进如何减少:
|
| Tab key performs auto-indent | 指定何时“Tab”键会自动缩进文本:
|
| Prefer single line comments | 当您的高亮定义文件同时包含多行和单行注释的定义时,请选择此选项,以便在将选定内容注释掉时应用单行注释的定义。 |
| Preferred comment position | 指定注释选定内容时单行注释的位置:
|
另请参阅 《如何:配置编辑器》、 《查找首选项》、《缩进文本或代码》、《指定Qt Quick 代码样式》、《配置编辑器》、《C++代码样式》和《Nim》。
Copyright © The Qt Company Ltd. and other contributors. 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.