【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
相关推荐
灵性花火1 小时前
记录Qt的多个bug
qt·bug
奥特曼狂扁小怪兽3 小时前
Qt 自定义无标题栏窗口:FramelessWidget 实现与解析
开发语言·qt
___波子 Pro Max.3 小时前
VS Code文件监视排除设置详解
vscode
泽虞5 小时前
《Qt应用开发》笔记
linux·开发语言·c++·笔记·qt
掘根6 小时前
【Qt】绘图
开发语言·qt
ajassi20007 小时前
开源 C++ QT QML 开发(十一)通讯--TCP服务器端
c++·qt·开源
蓝天智能8 小时前
QT MVC中View的特点及使用注意事项
开发语言·qt·mvc
larry_dongy9 小时前
【学习记录】vscode+ros2+cpp调试
vscode·学习
ajassi20009 小时前
开源 C++ QT QML 开发(十四)进程用途
c++·qt·开源
vortex510 小时前
vscode-background 扩展的原理、配置和使用
ide·vscode·编辑器