Reputation: 3632
I have a QTableView inside a layout itself inside a Widget. How I can set the Widget size after the call of tableView.resizeColumnsToContents() in order to have the same size of the table (and does not need a scrollbar ) Thanks
Upvotes: 0
Views: 2056
Reputation: 5452
If I understand properly what you want is to adjust the horizontal size of the container widget to the size of the table contents (which is not necessarily the table size). The following method works for me with a small table of 20 rows and 3 columns:
columnCount
method)columnWidth
method and compute the total width of the columnsSo the code would look like:
my_table_view.resizeColumnsToContents()
w = 0
for c in range(my_table_model.columnCount()):
w = w + my_table_view.columnWidth(c)
container_widget.resize(w + my_table_view.verticalHeader().width() + my_table_view.autoScrollMargin()*1.5, container_widget.size().height())
As I said, I'm assuming that you want to resize your widget horizontally.
Upvotes: 2