Change brace coding style in QtCreator
Asked Answered
M

3

14

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.

Mussorgsky answered 24/7, 2013 at 18:25 Comment(0)
E
1

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.

Encamp answered 18/12, 2013 at 2:11 Comment(0)
O
3

I've opened public suggestion at Qt Creator bug tracker -- https://bugreports.qt.io/browse/QTCREATORBUG-11033.

Think, that it would be more helpful to pay more attention to bug tracker.

Hope, this feature will be added in Qt Creator 3.0.

Ovid answered 9/12, 2013 at 9:25 Comment(2)
Nope, unfortunately it's not in Qt Creator 3.0Spongin
@Spongin Merged in 2014, you need to enable Beautifier in plugins menu.Wiggler
E
1

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.

Encamp answered 18/12, 2013 at 2:11 Comment(0)
S
0

As of recent Creator versions (not googled when this change was made) this is controlled by clang-format. This option hould control it.

Stearic answered 4/8, 2023 at 22:22 Comment(1)
It does not, BraceWrapping - AfterFunction should be used instead. Unfortunately, code added through "Refactor -> Add Definition" menu still has a brace on a separate line...Trygve

© 2022 - 2024 — McMap. All rights reserved.