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. QT Creator, mixed tabs/spaces alignment issue in Text Editor
Forum Updated to NodeBB v4.3 + New Features

QT Creator, mixed tabs/spaces alignment issue in Text Editor

Scheduled Pinned Locked Moved Solved Qt Creator and other tools
6 Posts 3 Posters 755 Views 2 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.
  • F Offline
    F Offline
    frejur
    wrote on last edited by frejur
    #1

    Hi,

    I am running the latest build of QT Creator 12 on Windows.

    I would like to use tabs for indentation and spaces for alignment, e.g.

    void test(int a,
    ..........int b,
    

    Instead I get something like:

    void test(int a,
    \t\t\t....int b
    

    ('\t' is tab, '.' is space)

    Below if a picture that should illustrate the problem I am experiencing, and how I've setup QT Creator.
    alt text

    Cheers,

    jsulmJ 1 Reply Last reply
    0
    • SGaistS SGaist

      @frejur hi,

      Mixing both is usually a bad idea. It will work for you because of the configuration of your editor but as soon as the tab is rendered with a different width, your alignement will be broken.

      You should rather use one or the other to keep things clean.

      F Offline
      F Offline
      frejur
      wrote on last edited by frejur
      #5

      @SGaist I respectfully disagree. It's not what I prefer personally, but there are codebases that enforce the kind of style I'm referring to.

      It seems like this is not supported or not implemented very well by the Text Editor's own auto-indent.

      Luckily it is supported by ClangFormat, but you need to disable all the other indentation related shenanigans.

      Here are the settings that worked for me:

      1. Disable Text Editor>Typing> Enable automatic indentation
      2. Disable Text Editor>Cleanups Upon Saving> Clean whitespace
      3. (If using FakeVim) Disable FakeVim>General>Vim Behaviour> Automatic indentation
      4. Enable C++>Code Style>ClangFormat settings> Format while typing, and Format edited code on file save
      5. In C++>Code Style, in the panel named ClangFormat, scroll way down and set:
        UseTab=ForIndentation
        
      6. In that same panel make sure to set ColumnLimit to whatever you're using, this does not sync with whatever you set up under Text Editor>Display.

      Note that the auto-alignment mostly only "kicks in" when the line you're editing exceeds the maximum column limit. E.g. If you are listing a bunch of arguments, they will always be put on a single line if they fit within the limit. But there's more freedom when it comes to string literals.

      It does seems to work though, you may have to trigger the alignment/indentation manually by hitting save.

      Unfortunately, statements using the stream insertion operator mess things up, but from what I gather that's due to a bug in ClangFormat.

      F 1 Reply Last reply
      0
      • F frejur

        Hi,

        I am running the latest build of QT Creator 12 on Windows.

        I would like to use tabs for indentation and spaces for alignment, e.g.

        void test(int a,
        ..........int b,
        

        Instead I get something like:

        void test(int a,
        \t\t\t....int b
        

        ('\t' is tab, '.' is space)

        Below if a picture that should illustrate the problem I am experiencing, and how I've setup QT Creator.
        alt text

        Cheers,

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #2

        @frejur Change "Tab policy" to "Spaces Only"...

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        F 1 Reply Last reply
        0
        • jsulmJ jsulm

          @frejur Change "Tab policy" to "Spaces Only"...

          F Offline
          F Offline
          frejur
          wrote on last edited by
          #3

          @jsulm When I do that I get:

          void test(int a,
          ..........int b) {
          ....int c = 0;
          }
          

          Instead of the desired:

          void test(int a,
          ..........int b) {
          \t int c = 0;
          }
          

          ('\t ' is tab, '.' is space)

          SGaistS 1 Reply Last reply
          0
          • F frejur

            @jsulm When I do that I get:

            void test(int a,
            ..........int b) {
            ....int c = 0;
            }
            

            Instead of the desired:

            void test(int a,
            ..........int b) {
            \t int c = 0;
            }
            

            ('\t ' is tab, '.' is space)

            SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #4

            @frejur hi,

            Mixing both is usually a bad idea. It will work for you because of the configuration of your editor but as soon as the tab is rendered with a different width, your alignement will be broken.

            You should rather use one or the other to keep things clean.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            F 1 Reply Last reply
            3
            • SGaistS SGaist

              @frejur hi,

              Mixing both is usually a bad idea. It will work for you because of the configuration of your editor but as soon as the tab is rendered with a different width, your alignement will be broken.

              You should rather use one or the other to keep things clean.

              F Offline
              F Offline
              frejur
              wrote on last edited by frejur
              #5

              @SGaist I respectfully disagree. It's not what I prefer personally, but there are codebases that enforce the kind of style I'm referring to.

              It seems like this is not supported or not implemented very well by the Text Editor's own auto-indent.

              Luckily it is supported by ClangFormat, but you need to disable all the other indentation related shenanigans.

              Here are the settings that worked for me:

              1. Disable Text Editor>Typing> Enable automatic indentation
              2. Disable Text Editor>Cleanups Upon Saving> Clean whitespace
              3. (If using FakeVim) Disable FakeVim>General>Vim Behaviour> Automatic indentation
              4. Enable C++>Code Style>ClangFormat settings> Format while typing, and Format edited code on file save
              5. In C++>Code Style, in the panel named ClangFormat, scroll way down and set:
                UseTab=ForIndentation
                
              6. In that same panel make sure to set ColumnLimit to whatever you're using, this does not sync with whatever you set up under Text Editor>Display.

              Note that the auto-alignment mostly only "kicks in" when the line you're editing exceeds the maximum column limit. E.g. If you are listing a bunch of arguments, they will always be put on a single line if they fit within the limit. But there's more freedom when it comes to string literals.

              It does seems to work though, you may have to trigger the alignment/indentation manually by hitting save.

              Unfortunately, statements using the stream insertion operator mess things up, but from what I gather that's due to a bug in ClangFormat.

              F 1 Reply Last reply
              0
              • F frejur has marked this topic as solved on
              • F frejur

                @SGaist I respectfully disagree. It's not what I prefer personally, but there are codebases that enforce the kind of style I'm referring to.

                It seems like this is not supported or not implemented very well by the Text Editor's own auto-indent.

                Luckily it is supported by ClangFormat, but you need to disable all the other indentation related shenanigans.

                Here are the settings that worked for me:

                1. Disable Text Editor>Typing> Enable automatic indentation
                2. Disable Text Editor>Cleanups Upon Saving> Clean whitespace
                3. (If using FakeVim) Disable FakeVim>General>Vim Behaviour> Automatic indentation
                4. Enable C++>Code Style>ClangFormat settings> Format while typing, and Format edited code on file save
                5. In C++>Code Style, in the panel named ClangFormat, scroll way down and set:
                  UseTab=ForIndentation
                  
                6. In that same panel make sure to set ColumnLimit to whatever you're using, this does not sync with whatever you set up under Text Editor>Display.

                Note that the auto-alignment mostly only "kicks in" when the line you're editing exceeds the maximum column limit. E.g. If you are listing a bunch of arguments, they will always be put on a single line if they fit within the limit. But there's more freedom when it comes to string literals.

                It does seems to work though, you may have to trigger the alignment/indentation manually by hitting save.

                Unfortunately, statements using the stream insertion operator mess things up, but from what I gather that's due to a bug in ClangFormat.

                F Offline
                F Offline
                frejur
                wrote on last edited by frejur
                #6

                Would love to edit my last reply, but can't due to the 3600s since last edit time restriction... Which should not be applicable since I posted two days ago?

                UseTab=ForIndentation seems to be more reliable than UseTab=AlignWithSpaces

                1 Reply Last reply
                1

                • Login

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