How to resize QWidget to fit its contents?
Basically I have a QTableWidget inside a QVBoxLayout. I set everything so that my table widget resizes to fit the contents. This is good, but I can't get my QWidget that hosts this table widget to resize itself to show everything.
I checked tablewidget.size() but the size is not the correct size, because if I use the same size for my QWidget, the table is cropped, i.e. I can't see it fully.
How can I achieve this?
Thanks in advance.
VRonin last edited by
lachdanan last edited by lachdanan
@VRonin Thanks a lot, you are right it works :) I have another issue about the row heights, I am trying to resize them but they don't seem to get smaller in height than this:
I am doing it like this:
hh = tableWidget.horizontalHeader()
hh.setFixedHeight(50) #hh.setStretchLastSection(True) vh = tableWidget.verticalHeader() vh.setSectionResizeMode(QtWidgets.QHeaderView.Fixed) vh.setDefaultSectionSize(1)
I don't understand why row heights refuse to get smaller.
and setDefaultSectionSize won't go under that value
so you must lower that first to go really low.
Thanks a lot I just tried that but no luck, and if I remove default section size function call, then they get larger:
This still looks same size for example.
When I used this it worked: vh.setSectionResizeMode(QtWidgets.QHeaderView.Stretch)