【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
相关推荐
技术探讨者19 小时前
极境导表工具 —— 让配置数据成为游戏开发的效率引擎
unity·编辑器·ai编程·游戏策划
Hua-Jay19 小时前
OpenCV联合C++/Qt 学习笔记(二十五)----加载深度神经网络模型及深度神经网络模型的使用
c++·笔记·qt·opencv·学习·计算机视觉·dnn
小牛蛋20 小时前
vcpkg 管理 PCL + VTK + Qt 开发三维点云可视化软件
开发语言·qt
AI小百科20 小时前
目前开源AI编辑器面临的主要挑战是什么
人工智能·开源·编辑器
接着奏乐接着舞20 小时前
vscode 给 Maven 启动的 JVM 加上 `-Dfile.encoding=UTF-8`
jvm·vscode·maven
爱吃龙利鱼20 小时前
MobaXterm连接ubuntu26.04无法在vim界面粘贴问题解决方法(粘贴会提示进入进入可视模式VISUAL))
linux·ubuntu·编辑器·vim
小许同学记录成长21 小时前
Qt 自研测控软件-配置测试项
开发语言·qt
郝学胜-神的一滴21 小时前
CMake 011:跨平台动态库编译
开发语言·c++·嵌入式硬件·qt·程序人生·cmake·liunx
秋921 小时前
Cursor 编辑器:下载、安装与深度使用详解
编辑器
ai安歌1 天前
鸿蒙PC:Qt适配OpenHarmony实战【昼刻】:用 Qt Quick 做一个可运行的鸿蒙时钟应用
qt·华为·harmonyos