Important: Please read the Qt Code of Conduct -

How to auto format my code

  • I was looking through my options when it comes to auto formatting code with Qt Creator and so far I have been unsuccessful. I realize that I can press Ctrl-I in order to fix indentation issues but I am looking for more. I tried getting Clang Format:

    sudo apt-get install clang-format
    Help -> About plugins->Beautifier

    it told me to restart Qt so I did, then I set a macro:

    Tools -> Options -> Environment -> Keyboard

    I searched for: "Format Current File" and recorded my macro to be Ctrl Y

    then I went back to my code, messed with the formatting and then tried my new macro... nothing happened. So then I tried going back to Beautifier to try the different tools for the Enable auto format on file save option, none of which seemed to do anything to my code. The code I am attempting to format is qml, please help.

  • Hi @Circuits

    Below is the details how i did it in windows.
    Write the clang script as you wish to and include it in project. Or you can use the one available online for Qt

    # Clang-format configuration style to be used by Qt,
    # based on the rules from and
    DISTFILES += \

    Please also enable ClangCodeModule

    help -> About plugin ->  ClangCodeModule


    I Use LLVM for clang format and in Qt -> Tools -> Options -> Beautifier Set the Clang format command.


    Then you can set the KeyBoard shortcut to it and it works.

    All the best.

  • Moderators

    @Circuits said in How to auto format my code:

    The code I am attempting to format is qml, please help.

    Beautifier is for C++ only.

    To do some simple auto formatting, either select all text and press Ctrl + i, or use reformat QML/JS option as described in

  • Banned

    This post is deleted!

  • @sierdzio Ah I see, dang, I was hoping I could do extensive auto reformatting of qml code.

Log in to reply