【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
相关推荐
Python图像识别6 小时前
40-【2027毕设】YOLO11面部口罩检测识别系统 - Python完整源码+PyQt5界面+训练模型+数据集
python·qt·课程设计
Vex2une6 小时前
PowerShell ISE 到 VS Code 迁移史:从集成脚本环境到现代编辑器工作流
windows·vscode·powershell·powershell ise·powershell 扩展·powershell 7·脚本编辑器
Python图像识别6 小时前
39-【2027毕设】YOLO11行人摔倒检测系统 - Python完整源码+PyQt5界面+训练模型+数据集
python·qt·课程设计
小李不困还能学11 小时前
VSCode远程开发免密码登录
ide·vscode·编辑器
?? Daisy12 小时前
Codex 接入第三方 API:CLI 与编辑器扩展的配置方法(2026-10)
编辑器
Quz16 小时前
QML PathView:直线路径与曲线路径
qt·动画·qml
扶尔魔ocy18 小时前
【qt openGL入门笔记】OSG实现飞机模型在网格图上飞行
qt·opengl·osg
西飘客1 天前
vs 怎么根据dll 生成lib文件
c++·qt
bkspiderx1 天前
Qt 插件机制:动态扩展应用功能的核心框架
开发语言·qt·元数据·qt 插件·qpluginloader