Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
QTableWidget white space - why and how?
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?
Can you post an image showing that white space ?
Lobstw last edited by Lobstw
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:
alex_malyu last edited by
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 )
@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?
alex_malyu last edited by
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.
@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
jkempinger_dv last edited by
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.