Search code examples
qtcoding-styleqt-creatorbraces

Change brace coding style in QtCreator


I want to change the braces coding style in Qt Creator 2.7.1. Currently, it is:

void bar(int i)
{
    static int counter = 0;
    counter += i;
}

But I want to change it to:

void bar(int i) {
    static int counter = 0;
    counter += i;
}

If I go to Options -> C++ -> Edit -> Braces, I can only change the indent of the braces. Changing the position of the braces manually in the preview text field, doesn't take any effect.


Solution

  • Artistic Style Plugin for Qt Creator IDE:

    1. Download plugin for your Qt Creator IDE version (for v2.7.1 download 2.7.0 version).

    2. Unpack.

    3. Edit dependency version description in ArtisticStyle.pluginspec into already-installed version:

      • On terminal (Ctrl+Alt+T) run qtcreator -version to get dependency version.

      • Example version description for v2.7.0:

        <dependency name="Core" version="2.7.0"/>
        <dependency name="TextEditor" version="2.7.0"/>
        <dependency name="ProjectExplorer" version="2.7.0"/>
        <dependency name="Qt4ProjectManager" version="2.7.0"/>
        

        Change to (for v2.7.1):

        <dependency name="Core" version="2.7.1"/>
        <dependency name="TextEditor" version="2.7.1"/>
        <dependency name="ProjectExplorer" version="2.7.1"/>
        <dependency name="Qt4ProjectManager" version="2.7.1"/>
        
    4. Follow the normal steps from website to install the plugin.

    5. Change the style through Preference -> Artistic… -> Style.

    6. Add your own style and add --style=java.