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?

Why is there a space in QTreeWidget?

Scheduled Pinned Locked Moved Solved General and Desktop
20 Posts 4 Posters 4.9k Views
  • 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
    5 May 2018, 08:20

    @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);

    T Offline
    T Offline
    Taz742
    wrote on 5 May 2018, 08:21 last edited by Taz742 5 May 2018, 08:24
    #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
      5 May 2018, 07:43

      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

      D Offline
      D Offline
      Diracsbracket
      wrote on 5 May 2018, 08:25 last edited by Diracsbracket 5 May 2018, 08:30
      #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 D 3 Replies Last reply 5 May 2018, 08:31
      2
      • M MasterBlade
        5 May 2018, 07:43

        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

        D Offline
        D Offline
        Diracsbracket
        wrote on 5 May 2018, 08:29 last edited by
        #10
        This post is deleted!
        1 Reply Last reply
        1
        • D Diracsbracket
          5 May 2018, 08:25

          @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 5 May 2018, 08:31 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
          • D Diracsbracket
            5 May 2018, 08:25

            @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 5 May 2018, 08:34 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
            • D Diracsbracket
              5 May 2018, 08:25

              @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);
              
              D Offline
              D Offline
              Diracsbracket
              wrote on 5 May 2018, 08:44 last edited by Diracsbracket 5 May 2018, 09:00
              #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 5 May 2018, 08:56
              0
              • D Diracsbracket
                5 May 2018, 08:44

                @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 5 May 2018, 08:56 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);
                
                D 1 Reply Last reply 5 May 2018, 08:57
                0
                • M MasterBlade
                  5 May 2018, 08:56

                  @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);
                  
                  D Offline
                  D Offline
                  Diracsbracket
                  wrote on 5 May 2018, 08:57 last edited by Diracsbracket 5 May 2018, 08:58
                  #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 5 May 2018, 09:17
                  1
                  • D Diracsbracket
                    5 May 2018, 08:57

                    @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 5 May 2018, 09:17 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
                    • D Diracsbracket
                      5 May 2018, 08:57

                      @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 5 May 2018, 09:20 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);

                      D 2 Replies Last reply 5 May 2018, 09:25
                      0
                      • M MasterBlade
                        5 May 2018, 09:20

                        @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);

                        D Offline
                        D Offline
                        Diracsbracket
                        wrote on 5 May 2018, 09:25 last edited by Diracsbracket 5 May 2018, 09:26
                        #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
                          5 May 2018, 09:20

                          @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);

                          D Offline
                          D Offline
                          Diracsbracket
                          wrote on 5 May 2018, 11:45 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 5 May 2018, 18:33
                          1
                          • D Diracsbracket
                            5 May 2018, 11:45

                            @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 5 May 2018, 18:33 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

                            17/20

                            5 May 2018, 09:20

                            • Login

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