设置步骤如下(环境为qt5.12.10):


创建.clang-format,放置在pro文件同一目录,保存即可自动改变代码格式,保证风格一致化。文件内容如下:
#https://clang.llvm.org/docs/ClangFormatStyleOptions.html
BasedOnStyle: LLVM
Standard: Cpp11
IndentPPDirectives: AfterHash
AllowShortFunctionsOnASingleLine: Empty
BinPackArguments: false
IndentWidth: 4
AlwaysBreakTemplateDeclarations: true
KeepEmptyLinesAtTheStartOfBlocks: false
MaxEmptyLinesToKeep: 1
ReflowComments: false
SpaceAfterCStyleCast: false
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: true
ColumnLimit: 100
AllowAllParametersOfDeclarationOnNextLine: true
AlignEscapedNewlines: Left
BinPackParameters: false
AccessModifierOffset: -4
FixNamespaceComments: true
#SpacesBeforeTrailingComments: 1
ReflowComments: false
BinPackParameters: false
PointerBindsToType: false
BreakBeforeBinaryOperators: NonAssignment
BreakBeforeBraces: Custom
BraceWrapping:AfterClass: trueAfterControlStatement: falseAfterEnum: falseAfterFunction: trueAfterNamespace: falseAfterObjCDeclaration: falseAfterStruct: falseAfterUnion: falseBeforeCatch: falseBeforeElse: falseIndentBraces: false
AlignAfterOpenBracket: true
AlwaysBreakTemplateDeclarations: true
NamespaceIndentation: None
SortIncludes: false
ForEachMacros: [ forever, foreach, Q_FOREACH, BOOST_FOREACH ]
注意:格式配置可按需自由修改配置,参考clang-format设置