this code in the constructor of my QWidget inherited class:


Qt Code:
  1. QHBoxLayout* hv = new QHBoxLayout(this);
  2. QTableWidget* tv = new QTableWidget(this);
  3. tv->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
  4.  
  5. tv->setSelectionBehavior(QAbstractItemView::SelectionBehavior::SelectItems);
  6. tv->setColumnCount(20);
  7. tv->setRowCount(20);
  8.  
  9. hv->addWidget(tv);
  10. setLayout(hv);
To copy to clipboard, switch view to plain text mode 

creates the tablewidget crammed in the upperleft corner like this:

https://i.imgur.com/ZWjY2mE.png


The tableview that stretches itself over the entire widget as it is supposed to has been created by QtCreator form designer. However, it uses the exact same code! I literally copied over the generated code into my class, but some how only the auto-generated widget stretches properly. Removing the generated one doesnt help either.



Now, why the hell doesnt it stretch correctly!? Seriously, this shit is driving my crazy.