Qt QTableWidget Column resizing

  1. Change the ResizeMode of the QHeaderView. For example, use:

horizontalHeader()->setResizeMode( 0, QHeaderView::Stretch );

to make the first column resize so the QTableWidget is always full.


  1. Override the resizeEvent and set the widths of each column yourself when the QTableWidget has been resized.

  1. To stretch last column:

    ui->tableWidget->horizontalHeader()->setStretchLastSection(true);
    
  2. To stretch column #n:

    ui->tableWidget->horizontalHeader()->setSectionResizeMode(n, QHeaderView::Stretch);
    

The best solution for this, in Qt5 you have to use setSectionResizeMode instead of setResizeMode

tabv = QTableView()
tabv.horizontalHeader().setSectionResizeMode(QHeaderView::Stretch)

Also you can specify the Stretch mode when resizing

tabv.horizontalHeader().resizeSections(QHeaderView::Stretch)