【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
相关推荐
lss_dgr19 小时前
vscode中ssh环境登录copilot没有反应的问题解决
ide·vscode·copilot
嵌入式×边缘AI:打怪升级日志21 小时前
Qt GUI 程序开发完全学习笔记(从环境搭建到第一个界面程序
qt
云淡风轻__1 天前
在 VSCode 中配置 LaTeX 环境的保姆级教程
ide·vscode·编辑器
嵌入式×边缘AI:打怪升级日志1 天前
使用文件 I/O 操作硬件 —— 从 LED 到温湿度传感器
qt·led·温湿度传感器
雒珣1 天前
Qt实现命令行参数功能示例:QCommandLineParser
开发语言·数据库·qt
水云桐程序员1 天前
一个GCC编译C语言命令的执行过程和错误输出:目录不存在:当前目录下没有output子目录|C语言编译的解决办法|Visual Studio Code
c语言·开发语言·vscode
史迪仔01121 天前
[QML] 交互事件深度解析:鼠标、键盘、拖拽
前端·c++·qt
一晌小贪欢1 天前
PyQt5 开发一个 PDF 批量合并工具
开发语言·qt·pdf
swift192211 天前
Qt多语言问题 —— 静态成员变量
开发语言·c++·qt
用户805533698031 天前
现代Qt开发教程(新手篇)1.4——容器
c++·qt