Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Sizing a window so that a contained QTableWidget fits without scroll bars
sipos last edited by
I have a window with a QTableWidget inside it and, I would like to set the window geometry such that the QTableWidget fits inside the window without having horizontal scroll bars. I've tried searching for info on how to do this but, I've not found anything (the abundance of questions about resizing the columns/rows of the QTableWidget doesn't help). If anyone can tell me how to do this, I'd be very grateful.
If you know the ideal size of your QTableWidget, you would use setFixeWidth
Hop it helps
sipos last edited by sipos
@SGaist I'd like to determine the size based on calling resizeColumnsToContents with the column headers set so that it fits the headers. I guess that this size will depend on platform.
Edit to clarify: I'd like to set the column headers, call resizeColumnsToContents() on the QTableWidget and then set the window size to be just the right size to contain it without horizontal scrollbars.
Since QTableWidget is a subclass of QAbstractScrollArea you could get the size you need from viewportSizeHint() or with