Qt个人配置

说明

该帖子是用来保存Qt的相关配置的,比如代码片段、快捷键等,用来进行新开发环境搭建时的参考

pic cheader

配置

代码片段

代码片段是使用相关的关键词进行触发的代码片段插入方法,在Qt中有一定的api支持,一般用于进行函数注释和文件头部注释等

  1. 文件头部注释

该片段注释一般用于新文件的项目、创建日期、文件名及文件说明等, 配置以及效果如下

pic cheader setting

文件头部注释配置

 1/*****************************************************
 2 * @Project: %{CurrentProject:Name} 
 3 *
 4 * @File: %{CurrentDocument:FileName}
 5 *
 6 * @Description:
 7 *
 8 * @Author: impressionyang
 9 *
10 * Created on %{CurrentDate:yyyy-MM-dd}
11 *
12 * Copyright (c) %{CurrentDate:yyyy} yangxy All rights reserved.
13 *****************************************************/

内容中的%{CurrentProject:Name}等即为Qt中内置的代码片段的接口,其功能与英文名意思一致

效果如下:

pic cheader

文件头部注释的效果

  1. 函数注释

函数注释一般用于指示函数功能,参数用意以及返回内容等

函数注释配置

函数注释配置

配置内容为:

1/*****************************************************
2 * @Function Name: 
3 *
4 * @brief 
5 *
6 * @param 
7 *
8 * @return 
9 *****************************************************/

使用效果如下

函数注释效果

函数注释效果

快捷键

快捷键一般用于一些功能的的直接触发,此次仅配置了代码格式化的功能

clang配置

clang格式化快捷键配置(与vscode配置一致)

补充:使用clang配置需要打开Qt Creator的插件beautifier(如下图), 然后才能在配置中添加clang的配置,需要添clang-formate的可执行文件(在vscode中提取,vscode安装插件C/C++即会自动安装)

安装beautifier

安装beautifier

配置beautifier

配置beautifier

.clangformat文件内容

  1---
  2Language:        Cpp
  3# BasedOnStyle:  WebKit
  4AccessModifierOffset: -2
  5AlignAfterOpenBracket: Align
  6AlignConsecutiveMacros: true
  7AlignConsecutiveAssignments: true
  8AlignConsecutiveBitFields: true
  9AlignConsecutiveDeclarations: true
 10AlignEscapedNewlines: Right
 11AlignOperands:   AlignAfterOperator
 12AlignTrailingComments: true
 13AllowAllArgumentsOnNextLine: true
 14AllowAllConstructorInitializersOnNextLine: true
 15AllowAllParametersOfDeclarationOnNextLine: true
 16AllowShortEnumsOnASingleLine: true
 17AllowShortBlocksOnASingleLine: Empty
 18AllowShortCaseLabelsOnASingleLine: false
 19AllowShortFunctionsOnASingleLine: All
 20AllowShortLambdasOnASingleLine: All
 21AllowShortIfStatementsOnASingleLine: Never
 22AllowShortLoopsOnASingleLine: false
 23AlwaysBreakAfterDefinitionReturnType: None
 24AlwaysBreakAfterReturnType: None
 25AlwaysBreakBeforeMultilineStrings: false
 26AlwaysBreakTemplateDeclarations: MultiLine
 27BinPackArguments: true
 28BinPackParameters: true
 29BraceWrapping:
 30  AfterCaseLabel:  true
 31  AfterClass:      true
 32  AfterControlStatement: Never
 33  AfterEnum:       true
 34  AfterFunction:   true
 35  AfterNamespace:  true
 36  AfterObjCDeclaration: false
 37  AfterStruct:     true
 38  AfterUnion:      true
 39  AfterExternBlock: true
 40  BeforeCatch:     false
 41  BeforeElse:      false
 42  BeforeLambdaBody: false
 43  BeforeWhile:     false
 44  IndentBraces:    false
 45  SplitEmptyFunction: true
 46  SplitEmptyRecord: true
 47  SplitEmptyNamespace: true
 48BreakBeforeBinaryOperators: All
 49BreakBeforeBraces: Custom
 50BreakBeforeInheritanceComma: false
 51BreakInheritanceList: BeforeColon
 52BreakBeforeTernaryOperators: true
 53BreakConstructorInitializersBeforeComma: false
 54BreakConstructorInitializers: BeforeComma
 55BreakAfterJavaFieldAnnotations: false
 56BreakStringLiterals: true
 57ColumnLimit:     130
 58CommentPragmas:  '^ IWYU pragma:'
 59CompactNamespaces: false
 60ConstructorInitializerAllOnOneLineOrOnePerLine: false
 61ConstructorInitializerIndentWidth: 2
 62ContinuationIndentWidth: 2
 63Cpp11BracedListStyle: false
 64DeriveLineEnding: true
 65DerivePointerAlignment: false
 66DisableFormat:   false
 67ExperimentalAutoDetectBinPacking: false
 68FixNamespaceComments: false
 69ForEachMacros:
 70  - foreach
 71  - Q_FOREACH
 72  - BOOST_FOREACH
 73IncludeBlocks:   Preserve
 74IncludeCategories:
 75  - Regex:           '^"(llvm|llvm-c|clang|clang-c)/'
 76    Priority:        2
 77    SortPriority:    0
 78  - Regex:           '^(<|"(gtest|gmock|isl|json)/)'
 79    Priority:        3
 80    SortPriority:    0
 81  - Regex:           '.*'
 82    Priority:        1
 83    SortPriority:    0
 84IncludeIsMainRegex: '(Test)?$'
 85IncludeIsMainSourceRegex: ''
 86IndentCaseLabels: false
 87IndentCaseBlocks: false
 88IndentGotoLabels: true
 89IndentPPDirectives: None
 90IndentExternBlock: AfterExternBlock
 91IndentWidth:     2
 92IndentWrappedFunctionNames: false
 93InsertTrailingCommas: None
 94JavaScriptQuotes: Leave
 95JavaScriptWrapImports: true
 96KeepEmptyLinesAtTheStartOfBlocks: true
 97MacroBlockBegin: ''
 98MacroBlockEnd:   ''
 99MaxEmptyLinesToKeep: 1
100NamespaceIndentation: Inner
101ObjCBinPackProtocolList: Auto
102ObjCBlockIndentWidth: 2
103ObjCBreakBeforeNestedBlockParam: true
104ObjCSpaceAfterProperty: true
105ObjCSpaceBeforeProtocolList: true
106PenaltyBreakAssignment: 2
107PenaltyBreakBeforeFirstCallParameter: 19
108PenaltyBreakComment: 300
109PenaltyBreakFirstLessLess: 120
110PenaltyBreakString: 1000
111PenaltyBreakTemplateDeclaration: 10
112PenaltyExcessCharacter: 1000000
113PenaltyReturnTypeOnItsOwnLine: 60
114PointerAlignment: Left
115ReflowComments:  true
116SortIncludes:    false
117SortUsingDeclarations: true
118SpaceAfterCStyleCast: false
119SpaceAfterLogicalNot: false
120SpaceAfterTemplateKeyword: true
121SpaceBeforeAssignmentOperators: true
122SpaceBeforeCpp11BracedList: true
123SpaceBeforeCtorInitializerColon: true
124SpaceBeforeInheritanceColon: true
125SpaceBeforeParens: ControlStatements
126SpaceBeforeRangeBasedForLoopColon: true
127SpaceInEmptyBlock: true
128SpaceInEmptyParentheses: false
129SpacesBeforeTrailingComments: 1
130SpacesInAngles:  false
131SpacesInConditionalStatement: false
132SpacesInContainerLiterals: true
133SpacesInCStyleCastParentheses: false
134SpacesInParentheses: false
135SpacesInSquareBrackets: false
136SpaceBeforeSquareBrackets: false
137Standard:        Latest
138StatementMacros:
139  - Q_UNUSED
140  - QT_REQUIRE_VERSION
141TabWidth:        8
142UseCRLF:         false
143UseTab:          Never
144WhitespaceSensitiveMacros:
145  - STRINGIZE
146  - PP_STRINGIZE
147  - BOOST_PP_STRINGIZE
148...

字体

在Qtcreator中也会安装我钟意的编程字体JetBrains Mono字体,下载后安装至系统中即可使用

字体配置

字体配置


impressionyang

版权

评论