Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Custom line-indentations with qmlformat.exe
Forum Updated to NodeBB v4.3 + New Features

Custom line-indentations with qmlformat.exe

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
qmlqmlformatformatter
3 Posts 2 Posters 1.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JustASimpleCoder
    wrote on 1 Jul 2020, 17:06 last edited by
    #1

    I was very excited to read that Qt 5.15.0 includes the new qmlformat.exe tool, and naturally I have been attempting to use it to format the QML files within my codebase.

    However, I noticed that this formatter tool sets all indentation as 4 spaces. The entire rest of my codebase (i.e. the C++ files, header files, JS files, etc.) all use 2 space indentations.

    Is there a way to tell qmlformat.exe to use 2 space indentations?

    There is surprisingly no documentation (as of 01-July-2020) on the Qt Forums regarding how to use this tool, and running qmlformat.exe --help does not provide an answer to setting custom line indentations.

    Any help would be welcomed!

    1 Reply Last reply
    0
    • T Offline
      T Offline
      thomaso
      wrote on 29 Oct 2021, 09:30 last edited by
      #2

      Hi, your question is one year old but I want to add a comment with hope it will get some attention. I am also happy that qmlformat is part of 5.15 version and also want to set custom indentation size.

      From what I saw, QmlJS formatter supports custom sizes, however CLI does not provide an option to set. Does anybody know a way how to set it up without the need to build qmlformat separately?

      Until this will be resolved, we still need to use 3rd party like https://github.com/jesperhh/qmlfmt or https://github.com/Orange-OpenSource/qmljsreformatter

      1 Reply Last reply
      0
      • T Offline
        T Offline
        thomaso
        wrote on 29 Oct 2021, 12:07 last edited by
        #3

        Hi @JustASimpleCoder, I received a quick response from Qt staff, it seems that Qt6.2 version of qmlformat contains what we need! :)

        ./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 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved