I'm having a few issues with sizing my QTableView subclass which is nested inside a few other widgets. What I'm trying to achieve is a TableView that increases it's vertical size to accommodate all the rows in the table. I've been able to get close to this, but not quite there. I have a suspicion that I am approaching some aspects of the problem the wrong way.

The basic layout of my Application is this:

MainWindow contains a TabWidget the Tabs have a ScrollArea which contains several collapsible panels in a vertical layout that serve as containers for various input widgets. Some of those panels contain my TableView class. In order to get the correct sizing for my TableVIew, I implemented SizeHint, and defined it as an override because otherwise it wouldn't be called at all. I'm fairly certain this is because Tables typically use SizeHintForIndex, SizeHintForColumn, and SizeHintForRow, but I really only need to base my sizing on the table itself, so hopefully this is an acceptable solution.

Qt Code:
  1. QSize PTableView::sizeHint() const{
  2. QSize size = QTableView::sizeHint();
  3. size.setHeight(defaultCellHeight * model()->rowCount() + 45);
  4. return size;
  5. }
To copy to clipboard, switch view to plain text mode 

The good news is this works perfectly when the widget is constructed. SizeHint is called appropriately, and the TableView is the correct vertical size (horizontal size isn't an issue as it simply takes up all available space). So my issue is that when the user adds a new row, or deletes a row, the size does not update. So I tried to make this connection to solve the problem:

Qt Code:
  1. connect(model, SIGNAL(rowsInserted(QModelIndex,int,int)), SLOT(recalculateSize()));
  2. connect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)), SLOT(recalculateSize()));
  3.  
  4. void PTableView::recalculateSize(){
  5. adjustSize();
  6. }
To copy to clipboard, switch view to plain text mode 

This produced undesirable results. The vertial size is correct for the TableView, but the container widget does not resize to match. Additionally, when the window is resized the widget reverts back to its constructed size.

So my question I suppose boils down to: how can I tell my widget to resize in the same way that it does when the tab is constructed? If I add a bunch of rows, close the project, then reopen it, the Table will have been resized to the correct size, so that is the sizing I need.

If need be, I can post my full classes or a compilable example, but I think I just need a push in the right direction to figure it out.