本页面

行为

要为没有 C++ 或 QML 代码的文本文件(如 Python 代码文件)指定缩进首选项,请选择Preferences >Text Editor >Behavior

文本编辑器首选项中的行为选项卡

您可以指定如何解释TabBackspace键的按下,以及如何对齐续行。

指定制表符首选项

您可以在以下级别指定制表符首选项:

  • 所有 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 时缩进减少的方式:
  • 要每次回退一个空格,请选择None
  • 要将前导空白处的缩进减少一级,请选择Follows Previous Indents
  • 如果光标左边的字符是空格,则要向后移动一个制表符长度,请选择Unindents
Tab key performs auto-indent指定Tab键何时自动缩进文本:
  • 要始终缩进文本,请选择Always
  • 要只在光标位于前导空白处时缩进文本,请选择In Leading White Space
  • 要永远不缩进文本,请选择Never
Prefer single line comments如果高亮定义文件中既有多行注释定义,也有单行注释定义,则选择此选项可在注释选区时应用单行注释定义。
Preferred comment position在注释选区时指定单行注释的位置:
  • 要让文件的高亮定义决定单行注释的位置,请选择Automatic 。如果没有高亮定义,注释将放在前导空白之后。
  • 要始终将单行注释放在前导空白之后,请选择After Whitespace
  • 要将单行批注放在行尾,请选择At Line Start

另请参阅 如何:配置编辑器查找首选项缩进文本或代码指定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.