【QML】vscode安装QML格式化插件方法

1. 安装插件

拓展 => 搜索qml => 找到QML Format =>点击安装

2. 配置

  • 打开settings.json文件
    • ctl + shift + p,然后搜索settings
  • 修改settings.js内容
c 复制代码
{
    ...
    //添加以下内容

    // 根据自己电脑安装路径来填写qmlformat.exe的路径,注意转义符"\" => "\\"
    "qmlFormat.command": "D:\\Soft\\Qt6\\5.15.2\\mingw81_64\\bin\\qmlformat.exe",

    // 命令选项,这里官方写的是--normal,但是报错,改成-n就好了
    // qmlFormat的命令选项见附录
    "qmlFormat.extraArguments": ["-n"]
}

3. 使用

  • 鼠标右键选择格式化文档
  • 快捷键 shift + alt + F

附录

  • qmlFormat.exe 命令选项
c 复制代码
./qmlformat -h                                       
Usage: ./qmlformat [options] filenames
Formats QML files according to the QML Coding Conventions.

Options:
  -h, --help                  Displays help on commandline options.
  --help-all                  Displays help including Qt specific options.
  -v, --version               Displays version information.
  -V, --verbose               Verbose mode. Outputs more detailed information.
  -i, --inplace               Edit file in-place instead of outputting to
                              stdout.
  -f, --force                 Continue even if an error has occurred.
  -t, --tabs                  Use tabs instead of spaces.
  -w, --indent-width <width>  How many spaces are used when indenting.
  -n, --normalize             Reorders the attributes of the objects according
                              to the QML Coding Guidelines.
  -F, --files <file>          Format all files listed in file, in-place
  -l, --newline <newline>     Override the new line format to use (native macos
                              unix windows).

Arguments:
  filenames                   files to be processed by qmlformat
相关推荐
小林ixn3 小时前
Node.js 文件系统与路径处理:从 API 到工程化实战
node.js·编辑器·vim
Luoxi_812 小时前
Anaconda超详细的安装教程+VScode的使用
ide·vscode·编辑器
blueman888815 小时前
qt5-serialbus详细解析
开发语言·网络·qt
无糖冰可乐2115 小时前
安装wsl2,并链接Windows上的vscode运行项目
pytorch·vscode·python·pip
流量猎手18 小时前
Vscode登陆服务器
服务器·ide·vscode
杜子不疼.1 天前
【Qt初识】信号槽(三):机制意义、断开连接与 Lambda 表达式
开发语言·数据库·qt
ljs6482739511 天前
Linux运维实操:vi编辑器永久配置静态IP(CentOS系列)
linux·运维·编辑器
诚信定制8391 天前
使用 CLion 内置性能分析工具观察新特性开销
编辑器
杜子不疼.1 天前
【Qt初识】信号槽(二):自定义信号函数与槽函数
开发语言·qt
秋田君1 天前
Qt_QVariant
开发语言·qt