Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Why is there a space in QTreeWidget?
Forum Updated to NodeBB v4.3 + New Features

Why is there a space in QTreeWidget?

Scheduled Pinned Locked Moved Solved General and Desktop
20 Posts 4 Posters 5.0k 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.
  • M MasterBlade

    @mrjj said in Why is there a space in QTreeWidget?:

    Hi
    You set the text to be center aligned
    twi->setTextAlignment(0, Qt::AlignCenter);
    so there will be spaces :)
    Try with AlignLeft and see.

    No way. I aligned to the left but still got space.
    And there are also spaces at the end of the row.
    0_1525507777399_1.PNG

    Taz742T Offline
    Taz742T Offline
    Taz742
    wrote on last edited by
    #6

    @MasterBlade
    Post code again.

    Do what you want.

    M 1 Reply Last reply
    1
    • Taz742T Taz742

      @MasterBlade
      Post code again.

      M Offline
      M Offline
      MasterBlade
      wrote on last edited by
      #7

      @Taz742 said in Why is there a space in QTreeWidget?:

      @MasterBlade
      Post code again.

      The codes are the same except that I removed the following line.
      twi->setTextAlignment(0, Qt::AlignCenter);

      Taz742T 1 Reply Last reply
      0
      • M MasterBlade

        @Taz742 said in Why is there a space in QTreeWidget?:

        @MasterBlade
        Post code again.

        The codes are the same except that I removed the following line.
        twi->setTextAlignment(0, Qt::AlignCenter);

        Taz742T Offline
        Taz742T Offline
        Taz742
        wrote on last edited by Taz742
        #8

        @MasterBlade said in Why is there a space in QTreeWidget?:

            twi->setTextAlignment(0, Qt::AlignCenter);
            twi->setTextAlignment(1, Qt::AlignCenter);
            twi->setTextAlignment(2, Qt::AlignCenter);
        }
        

        did you try this?

        twi->setTextAlignment(0, Qt::AlignLeft);
        twi->setTextAlignment(1, Qt::AlignLeft);
        twi->setTextAlignment(2, Qt::AlignLeft);
        

        Do what you want.

        1 Reply Last reply
        1
        • M MasterBlade

          Hello I have a QTreeWidget. But when I add items to it, there are always spaces before the 1st column and after the last column.

          Is there a way to remove them?
          0_1525506193278_1.PNG
          1_1525506193279_2.PNG

          DiracsbracketD Offline
          DiracsbracketD Offline
          Diracsbracket
          wrote on last edited by Diracsbracket
          #9

          @MasterBlade said in Why is there a space in QTreeWidget?:

          there are always spaces before the 1st column

          Try:

          ui->treeWidget->setRootIsDecorated(false); //is true by default, resulting in the space. This space is for a root-decoration image
          

          @MasterBlade said in Why is there a space in QTreeWidget?:

          and after the last column

          Try:

          ui->treeWidget->header()->setStretchLastSection(true);
          
          M DiracsbracketD 3 Replies Last reply
          2
          • M MasterBlade

            Hello I have a QTreeWidget. But when I add items to it, there are always spaces before the 1st column and after the last column.

            Is there a way to remove them?
            0_1525506193278_1.PNG
            1_1525506193279_2.PNG

            DiracsbracketD Offline
            DiracsbracketD Offline
            Diracsbracket
            wrote on last edited by
            #10
            This post is deleted!
            1 Reply Last reply
            1
            • DiracsbracketD Diracsbracket

              @MasterBlade said in Why is there a space in QTreeWidget?:

              there are always spaces before the 1st column

              Try:

              ui->treeWidget->setRootIsDecorated(false); //is true by default, resulting in the space. This space is for a root-decoration image
              

              @MasterBlade said in Why is there a space in QTreeWidget?:

              and after the last column

              Try:

              ui->treeWidget->header()->setStretchLastSection(true);
              
              M Offline
              M Offline
              MasterBlade
              wrote on last edited by
              #11

              @Diracsbracket said in Why is there a space in QTreeWidget?:

              setRootIsDecorated(false);

              This Worked!! Many Thanks!!

              However I'm still having spaces at the end of the row.

              Every time I run this function, the space grows bigger. Is there a way to fix this?
              0_1525509109468_1.PNG

              1 Reply Last reply
              0
              • DiracsbracketD Diracsbracket

                @MasterBlade said in Why is there a space in QTreeWidget?:

                there are always spaces before the 1st column

                Try:

                ui->treeWidget->setRootIsDecorated(false); //is true by default, resulting in the space. This space is for a root-decoration image
                

                @MasterBlade said in Why is there a space in QTreeWidget?:

                and after the last column

                Try:

                ui->treeWidget->header()->setStretchLastSection(true);
                
                M Offline
                M Offline
                MasterBlade
                wrote on last edited by
                #12

                @Diracsbracket said in Why is there a space in QTreeWidget?:

                @MasterBlade said in Why is there a space in QTreeWidget?:

                and after the last column

                Try:

                ui->treeWidget->header()->setStretchLastSection(true);
                

                Actually I already set this in Form View.
                0_1525509231624_2.PNG

                1 Reply Last reply
                0
                • DiracsbracketD Diracsbracket

                  @MasterBlade said in Why is there a space in QTreeWidget?:

                  there are always spaces before the 1st column

                  Try:

                  ui->treeWidget->setRootIsDecorated(false); //is true by default, resulting in the space. This space is for a root-decoration image
                  

                  @MasterBlade said in Why is there a space in QTreeWidget?:

                  and after the last column

                  Try:

                  ui->treeWidget->header()->setStretchLastSection(true);
                  
                  DiracsbracketD Offline
                  DiracsbracketD Offline
                  Diracsbracket
                  wrote on last edited by Diracsbracket
                  #13

                  @Diracsbracket said in Why is there a space in QTreeWidget?:

                  ui->treeWidget->header()->setStretchLastSection(true);

                  Sorry, this is true by default, so wouldn't help in your case.

                  @MasterBlade said in Why is there a space in QTreeWidget?:

                  However I'm still having spaces at the end of the row.

                  What value is returned by

                  qDebug()  << ui->treeWidget->columnCount() ;
                  

                  Somehow, it seems there is an extra empty column in your QTreeWidget ?

                  M 1 Reply Last reply
                  0
                  • DiracsbracketD Diracsbracket

                    @Diracsbracket said in Why is there a space in QTreeWidget?:

                    ui->treeWidget->header()->setStretchLastSection(true);

                    Sorry, this is true by default, so wouldn't help in your case.

                    @MasterBlade said in Why is there a space in QTreeWidget?:

                    However I'm still having spaces at the end of the row.

                    What value is returned by

                    qDebug()  << ui->treeWidget->columnCount() ;
                    

                    Somehow, it seems there is an extra empty column in your QTreeWidget ?

                    M Offline
                    M Offline
                    MasterBlade
                    wrote on last edited by
                    #14

                    @Diracsbracket said in Why is there a space in QTreeWidget?:

                    @Diracsbracket said in Why is there a space in QTreeWidget?:

                    ui->treeWidget->header()->setStretchLastSection(true);

                    Sorry, this is true by default, so wouldn't help in your case.

                    @MasterBlade said in Why is there a space in QTreeWidget?:

                    However I'm still having spaces at the end of the row.

                    What value is returned by

                    qDebug()  << ui->treeWidget->columnCount() ;
                    

                    Somehow, it seems there is an extra empty column in your QTreeWidget ?

                    I'm sorry but I'm having problem with the debugging. It won't pass.

                    ..\MasterZMDJ\deck.cpp:305:12: error: invalid use of incomplete type 'class QDebug'
                    qDebug() << ui->DeckList->columnCount() ;
                    ^

                    Also I added the following. The space is not growing as the function is called. But there is still a space at the end.

                    ui->DeckList->header()->setStretchLastSection(true);
                    
                    DiracsbracketD 1 Reply Last reply
                    0
                    • M MasterBlade

                      @Diracsbracket said in Why is there a space in QTreeWidget?:

                      @Diracsbracket said in Why is there a space in QTreeWidget?:

                      ui->treeWidget->header()->setStretchLastSection(true);

                      Sorry, this is true by default, so wouldn't help in your case.

                      @MasterBlade said in Why is there a space in QTreeWidget?:

                      However I'm still having spaces at the end of the row.

                      What value is returned by

                      qDebug()  << ui->treeWidget->columnCount() ;
                      

                      Somehow, it seems there is an extra empty column in your QTreeWidget ?

                      I'm sorry but I'm having problem with the debugging. It won't pass.

                      ..\MasterZMDJ\deck.cpp:305:12: error: invalid use of incomplete type 'class QDebug'
                      qDebug() << ui->DeckList->columnCount() ;
                      ^

                      Also I added the following. The space is not growing as the function is called. But there is still a space at the end.

                      ui->DeckList->header()->setStretchLastSection(true);
                      
                      DiracsbracketD Offline
                      DiracsbracketD Offline
                      Diracsbracket
                      wrote on last edited by Diracsbracket
                      #15

                      @MasterBlade said in Why is there a space in QTreeWidget?:

                      ..\MasterZMDJ\deck.cpp:305:12: error: invalid use of incomplete type 'class QDebug'

                      You must include <QDebug> to use qDebug().

                      If the column count is as expected, then it may be Qt bug. Which Qt version are you using? On which platform?

                      M 2 Replies Last reply
                      1
                      • DiracsbracketD Diracsbracket

                        @MasterBlade said in Why is there a space in QTreeWidget?:

                        ..\MasterZMDJ\deck.cpp:305:12: error: invalid use of incomplete type 'class QDebug'

                        You must include <QDebug> to use qDebug().

                        If the column count is as expected, then it may be Qt bug. Which Qt version are you using? On which platform?

                        M Offline
                        M Offline
                        MasterBlade
                        wrote on last edited by
                        #16

                        @Diracsbracket said in Why is there a space in QTreeWidget?:

                        @MasterBlade said in Why is there a space in QTreeWidget?:

                        ..\MasterZMDJ\deck.cpp:305:12: error: invalid use of incomplete type 'class QDebug'

                        You must include <QDebug> to use qDebug().

                        If the column count is as expected, then it may be Qt bug. Which Qt version are you using? On which platform?

                        The return value is 3.
                        I'm using Qt Creator 4.6.1. Based on Qt 5.10.1 (MSVC 2015,32 bit) on Windows 10 x64

                        1 Reply Last reply
                        0
                        • DiracsbracketD Diracsbracket

                          @MasterBlade said in Why is there a space in QTreeWidget?:

                          ..\MasterZMDJ\deck.cpp:305:12: error: invalid use of incomplete type 'class QDebug'

                          You must include <QDebug> to use qDebug().

                          If the column count is as expected, then it may be Qt bug. Which Qt version are you using? On which platform?

                          M Offline
                          M Offline
                          MasterBlade
                          wrote on last edited by
                          #17

                          @Diracsbracket said in Why is there a space in QTreeWidget?:

                          @MasterBlade said in Why is there a space in QTreeWidget?:

                          ..\MasterZMDJ\deck.cpp:305:12: error: invalid use of incomplete type 'class QDebug'

                          You must include <QDebug> to use qDebug().

                          If the column count is as expected, then it may be Qt bug. Which Qt version are you using? On which platform?

                          Oh I found the problem. It's on the sorting function.
                          When I comment this line, everything turns out just fine.
                          ui->DeckList->sortByColumn(1, Qt::AscendingOrder);

                          DiracsbracketD 2 Replies Last reply
                          0
                          • M MasterBlade

                            @Diracsbracket said in Why is there a space in QTreeWidget?:

                            @MasterBlade said in Why is there a space in QTreeWidget?:

                            ..\MasterZMDJ\deck.cpp:305:12: error: invalid use of incomplete type 'class QDebug'

                            You must include <QDebug> to use qDebug().

                            If the column count is as expected, then it may be Qt bug. Which Qt version are you using? On which platform?

                            Oh I found the problem. It's on the sorting function.
                            When I comment this line, everything turns out just fine.
                            ui->DeckList->sortByColumn(1, Qt::AscendingOrder);

                            DiracsbracketD Offline
                            DiracsbracketD Offline
                            Diracsbracket
                            wrote on last edited by Diracsbracket
                            #18

                            @MasterBlade said in Why is there a space in QTreeWidget?:

                            When I comment this line, everything turns out just fine.

                            Which in itself is weird... sorting should not affect the layout of the treeWidget in that way.

                            1 Reply Last reply
                            0
                            • M MasterBlade

                              @Diracsbracket said in Why is there a space in QTreeWidget?:

                              @MasterBlade said in Why is there a space in QTreeWidget?:

                              ..\MasterZMDJ\deck.cpp:305:12: error: invalid use of incomplete type 'class QDebug'

                              You must include <QDebug> to use qDebug().

                              If the column count is as expected, then it may be Qt bug. Which Qt version are you using? On which platform?

                              Oh I found the problem. It's on the sorting function.
                              When I comment this line, everything turns out just fine.
                              ui->DeckList->sortByColumn(1, Qt::AscendingOrder);

                              DiracsbracketD Offline
                              DiracsbracketD Offline
                              Diracsbracket
                              wrote on last edited by
                              #19

                              @MasterBlade said in Why is there a space in QTreeWidget?:

                              Oh I found the problem.

                              Could you put the question as solved then? Cheers!~

                              M 1 Reply Last reply
                              1
                              • DiracsbracketD Diracsbracket

                                @MasterBlade said in Why is there a space in QTreeWidget?:

                                Oh I found the problem.

                                Could you put the question as solved then? Cheers!~

                                M Offline
                                M Offline
                                MasterBlade
                                wrote on last edited by
                                #20

                                @Diracsbracket said in Why is there a space in QTreeWidget?:

                                @MasterBlade said in Why is there a space in QTreeWidget?:

                                Oh I found the problem.

                                Could you put the question as solved then? Cheers!~

                                Sure, thanks for the help!

                                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