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. QTableWidget white space - why and how?
Forum Update on Monday, May 27th 2025

QTableWidget white space - why and how?

Scheduled Pinned Locked Moved Unsolved General and Desktop
qtablewidgetpythonqabstractscroll
8 Posts 4 Posters 7.7k 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.
  • L Offline
    L Offline
    Lobstw
    wrote on 24 Apr 2016, 16:10 last edited by
    #1

    Hello,

    Using a QTableWidget with setSizeAdjustPolicy(QtWidgets.QAbstractScrollArea.AdjustToContents) adjusts the size of the table to fit contents. However, sometimes, there is white space left to the right or below the table.

    Why does this white space appear? And how can I get rid of it WITHOUT simply stretching the last section, because in tables with only 1 row you get a funny looking row that's too stretched.

    Is there some built-in way of resizing the table itself to have no extra space?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 24 Apr 2016, 21:04 last edited by
      #2

      Hi,

      Can you post an image showing that white space ?

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

      L 1 Reply Last reply 28 Apr 2016, 23:34
      0
      • S SGaist
        24 Apr 2016, 21:04

        Hi,

        Can you post an image showing that white space ?

        L Offline
        L Offline
        Lobstw
        wrote on 28 Apr 2016, 23:34 last edited by Lobstw
        #3

        @SGaist

        Possibly relevant that it's on Mac OS

        This is a table with only one row

        Another table:, this one has more rows than table height so there is a scrollbar. Is the space for the scrollbar?

        Similar table that has more rows than height available:

        1 Reply Last reply
        0
        • A Offline
          A Offline
          alex_malyu
          wrote on 29 Apr 2016, 02:35 last edited by
          #4

          Your first picture displays white space below the row because
          QTableView height > row+header height.
          The are 2 ways to avoid it - adjust header or row height
          or adjust height of the table ( you may need to set minimumSize first )
          setMinimumSize(QSize(0, 3)); // overrides minimum height of QTableView to 3 pixels

          It looks like second picture shows space where vertical scrollbar should be shown.
          I am not sure why it is not shown, If you deliberately hidden it should have not take any space.
          check what is set with

          Qt::ScrollBarPolicy verticalScrollBarPolicy () const
          void setVerticalScrollBarPolicy ( Qt::ScrollBarPolicy )

          L 1 Reply Last reply 29 Apr 2016, 20:48
          0
          • A alex_malyu
            29 Apr 2016, 02:35

            Your first picture displays white space below the row because
            QTableView height > row+header height.
            The are 2 ways to avoid it - adjust header or row height
            or adjust height of the table ( you may need to set minimumSize first )
            setMinimumSize(QSize(0, 3)); // overrides minimum height of QTableView to 3 pixels

            It looks like second picture shows space where vertical scrollbar should be shown.
            I am not sure why it is not shown, If you deliberately hidden it should have not take any space.
            check what is set with

            Qt::ScrollBarPolicy verticalScrollBarPolicy () const
            void setVerticalScrollBarPolicy ( Qt::ScrollBarPolicy )

            L Offline
            L Offline
            Lobstw
            wrote on 29 Apr 2016, 20:48 last edited by
            #5

            @alex_malyu My table is part of a GridLayout so resizing/setting minimum size didn't fix it. (I'd prefer not changing row size)

            If I set ScrollBarPolicy to AlwaysOff, then the space on the right is gone. But I see that the default policy is "as needed" and on Mac that usually means the transparent scroll bar appears over the content not with a seperate space for it. Is there some other setting for it in Qt or any way of recreating this interaction?

            A 1 Reply Last reply 29 Apr 2016, 21:39
            0
            • L Lobstw
              29 Apr 2016, 20:48

              @alex_malyu My table is part of a GridLayout so resizing/setting minimum size didn't fix it. (I'd prefer not changing row size)

              If I set ScrollBarPolicy to AlwaysOff, then the space on the right is gone. But I see that the default policy is "as needed" and on Mac that usually means the transparent scroll bar appears over the content not with a seperate space for it. Is there some other setting for it in Qt or any way of recreating this interaction?

              A Offline
              A Offline
              alex_malyu
              wrote on 29 Apr 2016, 21:39 last edited by
              #6

              @Lobstw

              setting minimum size would only allow it to be smaller ( you might want to compute desired height yourself.) If you are always working with a single row you can make it of fixed height / or set maximum size and spacer, but if you put it into layout where a few widget define the height, you need something to be resized instead of table view. You for example can put table view and vertical spacer into vertical layout in your grid layout instead of table view, but in the most cases this would result in even less attractive look.

              as for ScrollBarPolicy on Windows and Linux with Qt4 (I do not have access to Qt5 right now to test, but as far as I can recall it should be the same) scrollbar area takes away some space from available for cells space, but this only happens if scrollbar is visible (unless it is always on ).
              In your case behaviour corresponds to always on. Sounds like a bug.

              L 1 Reply Last reply 1 May 2016, 00:06
              0
              • A alex_malyu
                29 Apr 2016, 21:39

                @Lobstw

                setting minimum size would only allow it to be smaller ( you might want to compute desired height yourself.) If you are always working with a single row you can make it of fixed height / or set maximum size and spacer, but if you put it into layout where a few widget define the height, you need something to be resized instead of table view. You for example can put table view and vertical spacer into vertical layout in your grid layout instead of table view, but in the most cases this would result in even less attractive look.

                as for ScrollBarPolicy on Windows and Linux with Qt4 (I do not have access to Qt5 right now to test, but as far as I can recall it should be the same) scrollbar area takes away some space from available for cells space, but this only happens if scrollbar is visible (unless it is always on ).
                In your case behaviour corresponds to always on. Sounds like a bug.

                L Offline
                L Offline
                Lobstw
                wrote on 1 May 2016, 00:06 last edited by
                #7

                @alex_malyu Tried adding a spacer between my widgets and the space still remains :(

                I also think the scrollbar one is a bug because the same code works without ANY spaces on Windows and it's only Mac giving me grief

                1 Reply Last reply
                0
                • J Offline
                  J Offline
                  jkempinger_dv
                  wrote on 1 Sept 2017, 15:11 last edited by
                  #8

                  Has anyone found a solution to this? I'm using a QTableWidget on macOS and having the same issue. The table is always at least 76 pixels tall, even when the verticalHeader is smaller than that. Changing the minimum height for the table and/or the header (to something small like 3 pixels) doesn't change the table height; it's still 76. Once I add more rows (so that the height is > 76) the table works just fine.

                  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