【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
相关推荐
小贺儿开发6 小时前
Unity VideoPlayer 播放控制器
unity·编辑器·播放器·视频·工具·videoplayer·互动
Jun6268 小时前
QT(3)-线程中使用控件
开发语言·qt
Jun6268 小时前
QT(1)-C/C++库生成和调用
c语言·开发语言·c++·qt
Jun6268 小时前
QT(10)-TCP数据收发
开发语言·qt·tcp/ip
Littlehero_1218 小时前
QT自定义控件之热换站远程监控系统
c++·qt
努力努力再努力wz9 小时前
【Qt入门系列】一文掌握 Qt 常用显示类控件:QLCDNumber、QProgressBar 与 QCalendarWidget
c语言·开发语言·数据结构·数据库·c++·git·qt
仰望星空的凡人9 小时前
VSCODE接入Claude Code使用第三方模型教程
ide·vscode·ai智能体·claude code
C++ 老炮儿的技术栈9 小时前
如何利用 OpenCV 将图像显示在对话框窗口上
c语言·c++·人工智能·qt·opencv·计算机视觉·github
ALINX技术博客10 小时前
【黑金云课堂】FPGA技术教程Linux开发:NVMe/Qt/OpenCV人脸检测
linux·qt·fpga开发
Jun62611 小时前
QT(4)-EXCEL操作
开发语言·qt·excel