行为
要为没有 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.